Created
January 27, 2017 19:22
-
-
Save robwormald/1a65a207a9e77172b68cebb6bd98da4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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