文档位于https://github.com/pivotal/jasmine/wiki/Matchers包括以下内容:expect(function(){fn();}).toThrow(e);如thisquestion中所述,下面的代码不起作用,因为我们想传递一个函数对象给expect,而不是调用fn()的结果:expect(fn()).toThrow(e);以下是否有效?expect(fn).toThrow(e);如果我用doIt方法定义了一个对象thing,下面的操作是否有效?expect(thing.doIt).toThrow(e);(如果是这样,有没有办法将参数传递给doIt方
文档位于https://github.com/pivotal/jasmine/wiki/Matchers包括以下内容:expect(function(){fn();}).toThrow(e);如thisquestion中所述,下面的代码不起作用,因为我们想传递一个函数对象给expect,而不是调用fn()的结果:expect(fn()).toThrow(e);以下是否有效?expect(fn).toThrow(e);如果我用doIt方法定义了一个对象thing,下面的操作是否有效?expect(thing.doIt).toThrow(e);(如果是这样,有没有办法将参数传递给doIt方
是否可以在类私有(private)方法上使用Jasmine单元测试框架的spyon方法?文档给出了这个例子,但这可以灵活地用于私有(private)函数吗?describe("Person",function(){it("callsthesayHello()function",function(){varfakePerson=newPerson();spyOn(fakePerson,"sayHello");fakePerson.helloSomeone("world");expect(fakePerson.sayHello).toHaveBeenCalled();});});
是否可以在类私有(private)方法上使用Jasmine单元测试框架的spyon方法?文档给出了这个例子,但这可以灵活地用于私有(private)函数吗?describe("Person",function(){it("callsthesayHello()function",function(){varfakePerson=newPerson();spyOn(fakePerson,"sayHello");fakePerson.helloSomeone("world");expect(fakePerson.sayHello).toHaveBeenCalled();});});
expect(view.$el.html()).toContain('Admin');该View确实包含“Admin”一词,因此我希望它返回true。我怎样才能做到这一点?expect(view.$el.html()).toContain('Admin');这将返回undefined。我怎样才能让它返回true?HelpAdmin这是从view.$el.html返回的内容请帮忙。 最佳答案 toContain()现在canactuallybeusedforsubstringinstringchecks:expect(view.$el
expect(view.$el.html()).toContain('Admin');该View确实包含“Admin”一词,因此我希望它返回true。我怎样才能做到这一点?expect(view.$el.html()).toContain('Admin');这将返回undefined。我怎样才能让它返回true?HelpAdmin这是从view.$el.html返回的内容请帮忙。 最佳答案 toContain()现在canactuallybeusedforsubstringinstringchecks:expect(view.$el
我是Jasmine的新手和一般测试的新手。我的代码块检查我的库是否已使用new运算符实例化://if'this'isn'taninstanceofmylib...if(!(thisinstanceofmylib)){//returnanewinstancereturnnewmylib();}我如何使用Jasmine对此进行测试? 最佳答案 Jasmine>=3.5.0Jasmine提供了toBeInstanceOf匹配器。it("matchesanyvalue",()=>{expect(3).toBeInstanceOf(Numbe
我是Jasmine的新手和一般测试的新手。我的代码块检查我的库是否已使用new运算符实例化://if'this'isn'taninstanceofmylib...if(!(thisinstanceofmylib)){//returnanewinstancereturnnewmylib();}我如何使用Jasmine对此进行测试? 最佳答案 Jasmine>=3.5.0Jasmine提供了toBeInstanceOf匹配器。it("matchesanyvalue",()=>{expect(3).toBeInstanceOf(Numbe
我在实际代码中遇到过这个问题,但我举了一个简单的例子来证明这一点。下面的代码工作正常。我在我的根describe()block中设置了一个变量,该变量可在我的子describe()的it()中访问block。describe('simpleobject',function(){varorchard;beforeEach(function(){orchard={trees:{apple:10,orange:20},bushes:{boysenberry:40,blueberry:35}};});describe('trees',function(){it('shouldhaveapple
我在实际代码中遇到过这个问题,但我举了一个简单的例子来证明这一点。下面的代码工作正常。我在我的根describe()block中设置了一个变量,该变量可在我的子describe()的it()中访问block。describe('simpleobject',function(){varorchard;beforeEach(function(){orchard={trees:{apple:10,orange:20},bushes:{boysenberry:40,blueberry:35}};});describe('trees',function(){it('shouldhaveapple