jestjs

How do I compare two collections in Jest ignoring element order?

荒凉一梦 提交于 2021-01-20 04:15:18
问题 When writing a unit test in Jest, how can I test that an array contains exactly the expected values in any order ? In Chai , I can write: const value = [1, 2, 3]; expect(value).to.have.members([2, 1, 3]); What's the equivalent syntax in Jest? 回答1: Another way is to use the custom matcher .toIncludeSameMembers() from jest-community/jest-extended. Example given from the README test('passes when arrays match in a different order', () => { expect([1, 2, 3]).toIncludeSameMembers([3, 1, 2]); expect

“NoSuchSessionError: This driver instance does not have a valid session ID” when running a simple Selenium Runner test

萝らか妹 提交于 2021-01-19 05:27:11
问题 I just installed the latest version of Selenium Runner npm install -g selenium-side-runner on my Mac High Sierra. I'm running node v14.1.0. I'm using Chrome Driver v 83. I want to run a very simple file that simply opens a page, waiting for an element on that page to be present. However, I'm getting a "NoSuchSessionError: This driver instance does not have a valid session ID" error. The Selenium Runner .side file in question is $ cat selenium/KarmaDecayGetResults.side { "id": "9664bd47-b18f

“NoSuchSessionError: This driver instance does not have a valid session ID” when running a simple Selenium Runner test

天大地大妈咪最大 提交于 2021-01-19 05:26:57
问题 I just installed the latest version of Selenium Runner npm install -g selenium-side-runner on my Mac High Sierra. I'm running node v14.1.0. I'm using Chrome Driver v 83. I want to run a very simple file that simply opens a page, waiting for an element on that page to be present. However, I'm getting a "NoSuchSessionError: This driver instance does not have a valid session ID" error. The Selenium Runner .side file in question is $ cat selenium/KarmaDecayGetResults.side { "id": "9664bd47-b18f

“NoSuchSessionError: This driver instance does not have a valid session ID” when running a simple Selenium Runner test

和自甴很熟 提交于 2021-01-19 05:26:34
问题 I just installed the latest version of Selenium Runner npm install -g selenium-side-runner on my Mac High Sierra. I'm running node v14.1.0. I'm using Chrome Driver v 83. I want to run a very simple file that simply opens a page, waiting for an element on that page to be present. However, I'm getting a "NoSuchSessionError: This driver instance does not have a valid session ID" error. The Selenium Runner .side file in question is $ cat selenium/KarmaDecayGetResults.side { "id": "9664bd47-b18f

innerText is undefined in jest test

二次信任 提交于 2021-01-18 07:45:00
问题 When testing using jest I saw that the property innerText is undefined while not in test it has the right value. it('get text from div', () => { const div = document.createElement('DIV') div.innerHTML = '<br>a<br>b<br>c' console.log('innerText', div.innerText) // undefined console.log('textContent', div.textContent) // 'abc' // expect(getTextFromDiv(div).length).toMatchSnapshot() }) But when using the same code not in jest test, the innerText shows : 'a b c' and textContent is 'abc' . Why

innerText is undefined in jest test

一世执手 提交于 2021-01-18 07:42:06
问题 When testing using jest I saw that the property innerText is undefined while not in test it has the right value. it('get text from div', () => { const div = document.createElement('DIV') div.innerHTML = '<br>a<br>b<br>c' console.log('innerText', div.innerText) // undefined console.log('textContent', div.textContent) // 'abc' // expect(getTextFromDiv(div).length).toMatchSnapshot() }) But when using the same code not in jest test, the innerText shows : 'a b c' and textContent is 'abc' . Why

React testing: `fireEvent.focus(input)` does not change state

柔情痞子 提交于 2021-01-07 02:52:43
问题 I have create a number input component, but when I try to test it everything works great, except from the onMouserEnter() , onMouseOver() , onMouserLeave() and onFocus methods. On the component and on browser, the state changes (as I use the useState hook to know whether onHover), but on the tests no. Basically the state changes, but the children components that are meant to be displayed when onHover, do not display. Note: When I use a second conditional to display something, the test is able

React testing: `fireEvent.focus(input)` does not change state

烈酒焚心 提交于 2021-01-07 02:50:52
问题 I have create a number input component, but when I try to test it everything works great, except from the onMouserEnter() , onMouseOver() , onMouserLeave() and onFocus methods. On the component and on browser, the state changes (as I use the useState hook to know whether onHover), but on the tests no. Basically the state changes, but the children components that are meant to be displayed when onHover, do not display. Note: When I use a second conditional to display something, the test is able

Expected number of calls: >= 1 Received number of calls: 0

霸气de小男生 提交于 2021-01-07 02:40:54
问题 I am learning reactjs form with hooks, now I would like to test form on submit using jest and enzyme. here is my login component. import React from 'react' function Login() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); // ....api calLS } return ( <div> <form onSubmit={handleSubmit} className="login"> <input type="email" id="email-input" name="email" value={email} onChange={e => setEmail(e.target

Nest JS - Issue writing Jest Test Case for a function returning Observable Axios Response

十年热恋 提交于 2021-01-05 06:19:46
问题 I am fairly new to NestJS + Typescript + RxJs tech stack. I am trying to write a unit test case using Jest for one of my functions but not sure if doing it correctly. component.service.ts public fetchComponents(queryParams) { const url = this.prepareUrl(queryParams); const data$ = this.httpService.get(url); return data$ .pipe(map(({ data }) => data)); } component.sevice.spec.ts Test case works and passes describe('fetchComponents', () => { const query = { limit: 10, offset: 0 }; const result: