jest mock instance
//class.js
class MyClass {
methodOne() {
return 1;
}
methodTwo() {
return 2;
}
}
module.exports = MyClass;
// class.test.js
test('spy using class method', () => {
const result = new MyClass()
const spy = jest.spyOn(result, 'methodOne')
result.methodOne()
// check class method is call or not
expect(spy).toHaveBeenCalled()
// expect old value
expect(result.methodOne()).toBe(1)
// expect new value
spy.mockReturnValueOnce(12)
expect(result.methodOne()).toBe(12)
})test("mock.instances", () => {
const mockFn = jest.fn();
const a = new mockFn();
const b = new mockFn();
mockFn.mock.instances[0] === a;
mockFn.mock.instances[1] === b;
});
Also in JavaScript:
- js first letter uppercase
- mongodb unwind
- string concat javascript
- how to write a program that alerts the current month in words in javascript
- how to check if a kendo drop down is enabled js
- string to number angularjs
- javascript preencher array com 0
- js arrat push
- js check if undefined
- Can't bind to 'formGroup' since it isn't a known property of 'form'
- multiple case switch javascript
- get start of day javascript
- do you need a semicolon in javascript
- <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^(\.well-known/.*)$ $1 [L] RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] </IfModule>
- animate in jquery
- .filter js
- arraylist to json array
- jest manual mock node module
- number is even or odd fucntion in javascript
- javascript alphabet to number
- random image and link js
- javascript combine objects
- run length encoding javascript
- node mongoose save document