如何使用Jasmine来测试是否创建了实例? [英] How to use Jasmine to test if an instance is created?
本文介绍了如何使用Jasmine来测试是否创建了实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我是使用茉莉花的新手.问题如下:我有许多模块,通过RequireJS管理.现在,模块A在其中创建另一个模块B的实例.是否可以使用Jasmine来测试是否在A中创建了B的实例?为了传达更清晰的代码概念,我们有:
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};
});
现在,我该如何使用Jasmine来测试该模块A,并创建模块B的实例?预先感谢!
Now, how do i use Jasmine to test that module A indeed, creates an instance of module B? Thanks in advance!
致谢
推荐答案
这是在Jasmine测试中检查对象类型的一种方法:
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);
});
});
这篇关于如何使用Jasmine来测试是否创建了实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文