当前位置:网站首页>Using jasmine to monitor constructors - spying on a constructor using Jasmine
Using jasmine to monitor constructors - spying on a constructor using Jasmine
2022-07-03 03:20:00 【Zafo】
problem :
I am using Jasmine to test if certain objects are created and methods are called on them. I am using Jasmine To test whether some objects are created and their methods are called .
I have a jQuery widget that creates flipcounter objects and calls the setValue method on them. I have one jQuery The widget , It creates flipcounter Object and call their setValue Method .The code for flipcounter is here: https://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.jsflipcounter The code is here : https ://bitbucket.org/cnanney/apple-style-flip-counter/src/13fd00129a41/js/flipcounter.js
The flipcounters are created using:flipcounters Create :
var myFlipCounter = new flipCounter("counter", {inc: 23, pace: 500});
I want to test that the flipcounters are created and the setValue method is called on them. I want to test creation flipcounters And call setValue Method .My problem is that how do I spy on these objects even before they are created? My problem is how to monitor these objects before creating them ?Do I spy on the constructor and return fake objects? Will I monitor constructors and return fake objects ?Sample code would really help. The sample code will really help .Thanks for your help! Thanks for your help !:):)
Update: to update :
I've tried spying on the flipCounter like this: I've tried surveillance like this flipCounter 了 :
myStub = jasmine.createSpy('myStub');spyOn(window, 'flipCounter').andReturn(myStub);//expectationexpect(window.flipCounter).toHaveBeenCalled();
Then testing for the setValue call by flipCounter: And then through flipCounter test setValue call :
spyOn(myStub, 'setValue');//expectationexpect(myStub.setValue).toHaveBeenCalled();
the first test for initializing flipCounter is fine, but for testing the setValue call, all I'm getting is a 'setValue() method does not exist' error. initialization flipCounter The first test of is very good , But to test setValue call , What I got was 'setValue() Method does not exist ' error .Am I doing this the right way? Is it right for me to do this ?Thanks! thank you !
Solution :
Reference resources : https://stackoom.com/en/question/dDkF边栏推荐
- Réglez la hauteur et lancez le système. Currenttimemillis catton
- [mathematical logic] predicate logic (individual word | individual domain | predicate | full name quantifier | existence quantifier | predicate formula | exercise)
- How to make backgroundworker return an object
- 二维数组中的元素求其存储地址
- What happens between entering the URL and displaying the page?
- [combinatorics] number of solutions of indefinite equations (number of combinations of multiple sets R | number of non negative integer solutions of indefinite equations | number of integer solutions
- Vs Code configure virtual environment
- Pytoch configuration
- Left connection, inner connection
- Pat class B "1104 forever" DFS optimization idea
猜你喜欢
VS 2019 配置tensorRT生成engine
Idea set method call ignore case
Elsevier latex submitted the article pdftex def Error: File `thumbnails/cas-email. jpeg‘ not found: using draf
On the adjacency matrix and adjacency table of graph storage
Don't use the new Dede collection without the updated Dede plug-in
敏捷认证(Professional Scrum Master)模拟练习题-2
Application of derivative in daily question
【PyG】理解MessagePassing过程,GCN demo详解
MySQL practice 45 lecture [transaction isolation]
Why does thread crash not cause JVM crash
随机推荐
Limit of one question per day
About HTTP cache control
PHP constructor with parameters - PHP constructor with a parameter
程序员新人上午使用 isXxx 形式定义布尔类型,下午就被劝退?
How to make backgroundworker return an object
Basic information of Promethus (I)
MySql实战45讲【全局锁和表锁】
Pat class B common function Usage Summary
C # general interface call
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
Don't use the new Dede collection without the updated Dede plug-in
Opengauss database development and debugging tool guide
敏捷认证(Professional Scrum Master)模拟练习题-2
Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
MySql實戰45講【SQL查詢和更新執行流程】
Section 26 detailed explanation and demonstration of IPSec virtual private network configuration experiment - simulation experiment based on packettracer8.0
VS 2019配置tensorRT
node 开启服务器
QT based tensorrt accelerated yolov5