问题
Hi Am new to using Jasmine. The issue is as follows: I have a number of modules, managed through RequireJS. Now a module A creates an instance of another module B in it. Is it possible to use Jasmine to test whether an instance of B is being created in A? To convey a clearer idea of the code, we have:
//In module A
define(['B',],function(B){
function test(){
var newTest = new B();
};
return {test: test};
});
Now, how do i use Jasmine to test that module A indeed, creates an instance of module B? Thanks in advance!
Regards
回答1:
Here's one way to check the type of an object in a Jasmine test:
describe('ChocolateFactory', function() {
it('creates an instance of Chocolate', function() {
var factory = new ChocolateFactory();
var chocolate = factory.makeChocolate();
expect(chocolate instanceof Chocolate).toBe(true);
});
});
来源:https://stackoverflow.com/questions/23062034/how-to-use-jasmine-to-test-if-an-instance-is-created