当前位置:网站首页>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边栏推荐
- Opengauss database development and debugging tool guide
- labelme标记的文件转换为yolov5格式
- How to make backgroundworker return an object
- TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
- 复选框的使用:全选,全不选,选一部分
- LVGL使用心得
- 基于Qt的yolov5工程
- MySql实战45讲【索引】
- MySql实战45讲【SQL查询和更新执行流程】
- 力扣------网格中的最小路径代价
猜你喜欢
C programming learning notes [edited by Mr. Tan Haoqiang] (Chapter III sequence programming) 05 data input and output
Vs 2019 configuration du moteur de génération de tensorrt
Limit of one question per day
Summary of matrix knowledge points in Chapter 2 of Linear Algebra (Jeff's self perception)
Use of El tree search method
Idea set method call ignore case
机械臂速成小指南(八):运动学建模(标准DH法)
MySql實戰45講【SQL查詢和更新執行流程】
idea 加载不了应用市场解决办法(亲测)
Left connection, inner connection
随机推荐
Chart. JS multitooltip tag - chart js multiTooltip labels
Find the storage address of the elements in the two-dimensional array
Destroy the session and empty the specified attributes
Node start server
What happens between entering the URL and displaying the page?
open file in 'w' mode: IOError: [Errno 2] No such file or directory
Force freeing memory in PHP
Edit and preview in the back pipe to get the value writing method of the form
New programmers use the isXXX form to define Boolean types in the morning, and are discouraged in the afternoon?
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
Spark on yarn资源优化思路笔记
Vs 2019 installation and configuration opencv
Creation and destruction of function stack frame
Idea set method call ignore case
900w+ data, from 17s to 300ms, how to operate
Yolov5 project based on QT
Vs 2019 configuration tensorrt
Pytoch lightweight visualization tool wandb (local)
模型转换onnx2engine
Docker install redis