草庐IT

javascript - Jasmine 的 toThrow 匹配器是否需要将参数包装在匿名函数中?

文档位于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方

javascript - Jasmine 的 toThrow 匹配器是否需要将参数包装在匿名函数中?

文档位于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方

javascript - 在私有(private)方法上使用 Jasmine spyon

是否可以在类私有(private)方法上使用Jasmine单元测试框架的spyon方法?文档给出了这个例子,但这可以灵活地用于私有(private)函数吗?describe("Person",function(){it("callsthesayHello()function",function(){varfakePerson=newPerson();spyOn(fakePerson,"sayHello");fakePerson.helloSomeone("world");expect(fakePerson.sayHello).toHaveBeenCalled();});});

javascript - 在私有(private)方法上使用 Jasmine spyon

是否可以在类私有(private)方法上使用Jasmine单元测试框架的spyon方法?文档给出了这个例子,但这可以灵活地用于私有(private)函数吗?describe("Person",function(){it("callsthesayHello()function",function(){varfakePerson=newPerson();spyOn(fakePerson,"sayHello");fakePerson.helloSomeone("world");expect(fakePerson.sayHello).toHaveBeenCalled();});});

javascript - Jasmine 测试检查 html 是否包含文本并返回 bool 值

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

javascript - Jasmine 测试检查 html 是否包含文本并返回 bool 值

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

javascript - 使用 Jasmine 测试 instanceof

我是Jasmine的新手和一般测试的新手。我的代码块检查我的库是否已使用new运算符实例化://if'this'isn'taninstanceofmylib...if(!(thisinstanceofmylib)){//returnanewinstancereturnnewmylib();}我如何使用Jasmine对此进行测试? 最佳答案 Jasmine>=3.5.0Jasmine提供了toBeInstanceOf匹配器。it("matchesanyvalue",()=>{expect(3).toBeInstanceOf(Numbe

javascript - 使用 Jasmine 测试 instanceof

我是Jasmine的新手和一般测试的新手。我的代码块检查我的库是否已使用new运算符实例化://if'this'isn'taninstanceofmylib...if(!(thisinstanceofmylib)){//returnanewinstancereturnnewmylib();}我如何使用Jasmine对此进行测试? 最佳答案 Jasmine>=3.5.0Jasmine提供了toBeInstanceOf匹配器。it("matchesanyvalue",()=>{expect(3).toBeInstanceOf(Numbe

javascript - 使用 Jasmine 监视构造函数

我正在使用Jasmine来测试是否创建了某些对象并调用了它们的方法。我有一个jQuery小部件,它创建flipcounter对象并调用它们的setValue方法。flipcounter的代码在这里:https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js翻转计数器是使用以下方法创建的:varmyFlipCounter=newflipCounter("counter",{inc:23,pace:500});我想测试是否已创建翻转计数器并在其上调用了setValue方法

javascript - 使用 Jasmine 监视构造函数

我正在使用Jasmine来测试是否创建了某些对象并调用了它们的方法。我有一个jQuery小部件,它创建flipcounter对象并调用它们的setValue方法。flipcounter的代码在这里:https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js翻转计数器是使用以下方法创建的:varmyFlipCounter=newflipCounter("counter",{inc:23,pace:500});我想测试是否已创建翻转计数器并在其上调用了setValue方法