Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created January 27, 2017 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/1a65a207a9e77172b68cebb6bd98da4d to your computer and use it in GitHub Desktop.
Save robwormald/1a65a207a9e77172b68cebb6bd98da4d to your computer and use it in GitHub Desktop.
import {mock, module} from 'angular';
import {NG1_MODULE, NG1Service} from './ng1.service';
// One option is to mock out the downgraded services when testing in AngularJS
const mockModule = module('mockNg2Module', [])
.service('ng2service', class MockNg2Service {
getMessage() { return 'Always look on the bright side of life.'; }
});
describe('test ng1 service', () => {
let service: NG1Service;
beforeEach(mock.module(NG1_MODULE, mockModule.name));
beforeEach(mock.inject(
function (_ng1service_: NG1Service) {
service = _ng1service_;
}
));
it('(ng1) should return the right test message', () => {
expect(service.getServiceMessage()).toBe('This is the NG1 Service.');
});
it('should return the injected message', () => {
expect(service.getNg2Message()).toBe('Always look on the bright side of life.');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment