I have been working on writing unit tests for my angularJS 1.4.x app's Services and Controllers. The issue I am facing is that all our controllers and services are declared within modules, as shown in the example below under "MyApp".
module MyApp {
'user strict';
export class MyService {
public static $inject = [
'$http',
'$rootScope',
'library'
];
constructor(private $rootScope:any,
private $http:ng.IHttpService,
private library:lib.Library) {}
// some methods...
}
}
However, when attempting to require this file in my test.js file, I encounter the following error:
SyntaxError: Unexpected token, expected ";" (1:7)
Below is a snippet from my test file:
require('../../../node_modules/angular/angular.min.js');
require('../../../node_modules/angular-mocks/angular-mocks.js');
require('../ts/MyService.ts');
describe('Testing MyService', function(){
beforeEach(
angular.mock.module('app')
);
var service;
beforeEach(inject(function(myService) {
service = myService;
}));
it('Adding 1 + 1 should equal 2', function(){
var result = service.addTwoNumbers(1,1);
expect(result).toEqual(2);
});
});