Jasmine
4465 ワード
describe(string,function)/suiteテストセット、複数のSpecs(it)を含むことができ、各Specs(it)は複数のexpectを含むことができる
beforeAll,beforeEach,afterAll,afterEach//beforeAll:各suite(すなわちdescribe)のすべてのspec(すなわちit)が実行される前に実行され、beforeEach:各spec(すなわちit)が実行される前に実行される
angular-mocks.js
inject
url:http://jasmine.github.io/2.0/introduction.html
https://docs.angularjs.org/api/ngMock
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
beforeAll,beforeEach,afterAll,afterEach//beforeAll:各suite(すなわちdescribe)のすべてのspec(すなわちit)が実行される前に実行され、beforeEach:各spec(すなわちit)が実行される前に実行される
(function(){
describe("Test 'this'", function() {
beforeEach(function() {
this.testCount = this.testCount || 0;
this.testCount++;
});
afterEach(function() {
//this.testCount = 0; // , , this spec beforeEach/it/afterEach
});
it("Spec 1", function() {
expect(this.testCount).toBe(1);
});
it("Spec 2", function() {
expect(this.testCount).toBe(1);
});
});
})();
angular-mocks.js
inject
angular.module('myApplicationModule', [])
.value('mode', 'app')
.value('version', 'v1.0.1');
describe('MyApp', function() {
// You need to load modules that you want to test,
// it loads only the "ng" module by default.
beforeEach(module('myApplicationModule'));
// inject() is used to inject arguments of all given functions
it('should provide a version', inject(function(mode, version) {
expect(version).toEqual('v1.0.1');
expect(mode).toEqual('app');
}));
// The inject and module method can also be used inside of the it or beforeEach
it('should override a version and test the new version is injected', function() {
// module() takes functions or strings (module aliases)
module(function($provide) {
$provide.value('version', 'overridden'); // override version here
});
inject(function(version) {
expect(version).toEqual('overridden');
});
});
});
url:http://jasmine.github.io/2.0/introduction.html
https://docs.angularjs.org/api/ngMock