mocha.js

How to test async code with mocha using await

你。 提交于 2021-02-17 15:13:17
问题 How do I test async code with mocha? I wanna use multiple await inside mocha var assert = require('assert'); async function callAsync1() { // async stuff } async function callAsync2() { return true; } describe('test', function () { it('should resolve', async (done) => { await callAsync1(); let res = await callAsync2(); assert.equal(res, true); done(); }); }); This produces error below: 1) test should resolve: Error: Resolution method is overspecified. Specify a callback *or* return a Promise;

How to test async code with mocha using await

孤者浪人 提交于 2021-02-17 15:13:03
问题 How do I test async code with mocha? I wanna use multiple await inside mocha var assert = require('assert'); async function callAsync1() { // async stuff } async function callAsync2() { return true; } describe('test', function () { it('should resolve', async (done) => { await callAsync1(); let res = await callAsync2(); assert.equal(res, true); done(); }); }); This produces error below: 1) test should resolve: Error: Resolution method is overspecified. Specify a callback *or* return a Promise;

How to test async code with mocha using await

大憨熊 提交于 2021-02-17 15:12:17
问题 How do I test async code with mocha? I wanna use multiple await inside mocha var assert = require('assert'); async function callAsync1() { // async stuff } async function callAsync2() { return true; } describe('test', function () { it('should resolve', async (done) => { await callAsync1(); let res = await callAsync2(); assert.equal(res, true); done(); }); }); This produces error below: 1) test should resolve: Error: Resolution method is overspecified. Specify a callback *or* return a Promise;

Protractor - Find all elements and loop length of found elements and click button

北慕城南 提交于 2021-02-17 05:36:07
问题 So I have been trying to figure out on how to click a button x times depending on how many find All elements are. Meaning if there is 3 elements that is found by the same classname then we loop 3 times which should click the button 3 times. I have done something like this: (New update, check edit post at the bottom) Usually the element.all(by.className('btn btn-remove btn-outlined')).getText() is 3 but can be changed to 6 and random numbers so my idea was to read first how many btn btn-remove

Protractor - Find all elements and loop length of found elements and click button

被刻印的时光 ゝ 提交于 2021-02-17 05:35:09
问题 So I have been trying to figure out on how to click a button x times depending on how many find All elements are. Meaning if there is 3 elements that is found by the same classname then we loop 3 times which should click the button 3 times. I have done something like this: (New update, check edit post at the bottom) Usually the element.all(by.className('btn btn-remove btn-outlined')).getText() is 3 but can be changed to 6 and random numbers so my idea was to read first how many btn btn-remove

how to use jsdom to test functions with 'document'

会有一股神秘感。 提交于 2021-02-11 15:43:59
问题 I have a small question.. I am trying to test some functions I created (written in Typescript), and I am using mocha/chai/jsdom. Now, I get an error while testing functions with 'document' inside the document.. I get the message 'ReferenceError: document is not defined'. How can I still test these functions with 'document' in it? For example: [prompt.spec.ts] import { expect } from 'chai' import { JSDOM } from 'jsdom' import { functionX } from './functions' describe('Functions', () => { it(

Mocha, “require is not defined” when test in browser

杀马特。学长 韩版系。学妹 提交于 2021-02-11 14:41:42
问题 I'm using Mocha 5.2.0, npm 6.1.0, and I'm trying to test in Chrome browser. But When I run the test, the browser says "require is not defined". I want to see the test result in browser, but it works in terminal. I'm not using build system like webpack etc. test/test.js var assert = require("assert"); describe("Array", function() { describe("#indexOf()", function() { it("should return -1 when the value is not present", function() { assert.equal([1,2,3].indexOf(4), -1); }); }); }); index.html .

Issue running node.js unit tests in Visual Studio

非 Y 不嫁゛ 提交于 2021-02-11 13:37:37
问题 I tried asking a slightly more specific question here that has not received any answers so I'll try a little more generalized question. I'm new to unit testing in node.js and just following some simple demo's. For some reason I encounter issues when trying to include more than one describe in test file or when nesting them. The other link I referenced above was for multiple describes in a file causing tests in other files to fail for some odd reason. I also have issues nesting. I created a

Issue running node.js unit tests in Visual Studio

送分小仙女□ 提交于 2021-02-11 13:33:17
问题 I tried asking a slightly more specific question here that has not received any answers so I'll try a little more generalized question. I'm new to unit testing in node.js and just following some simple demo's. For some reason I encounter issues when trying to include more than one describe in test file or when nesting them. The other link I referenced above was for multiple describes in a file causing tests in other files to fail for some odd reason. I also have issues nesting. I created a

Yarn Berry - Run a Node Script Directly

☆樱花仙子☆ 提交于 2021-02-11 12:01:28
问题 Yarn berry (v2) got rid of node_modules (which I really love) by introducing pnp. However, scripts executed by node directly don't understand pnp modules, so you have to use yarn to run such a script. Is there some way (e.g. a require script like ts-node provides) so that I can still use node to launch my script that requires pnp modules? Background is that I want to configure the Mocha Sidebar extension for VS Code to support pnp. I can add configure node options there and specify files that