Category : jestjs

I am getting an error when I try running jest to test a file that was originally used for Mocha: ‚óŹ Test suite failed to run /Users/[user]/Repos/[repo]/node_modules/hubot-auth/index.coffee:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){fs = require ‘fs’ SyntaxError: Unexpected string 11 | const init = require(‘../../scripts/admin’); 12 | const auth_middleware = require(‘../../scripts/auth_middleware’); > 13 | const hubot_auth = require(‘hubot-auth’); | ^ ..

Read more

I’m very new to testing with Jest. I want to make a test to see if the following function returns user data from the database I have: let dbConnect = require(‘../config/dbConnect’); let findUserByEmail = (email) => { return new Promise(async (resolve, reject) => { try { dbConnect.query("SELECT * FROM user_login WHERE email = ?", email, ..

Read more

I have an endpoint in ExpressJS which return me an array of elements, but only this elements where type is this same as type in request query params, here is code, the endpoint return this array: [ { "type":[1,2] } ] GET request looks like this: http://localhost:3000/api/types?type=1&type=2 how to test this endpoint? I need to ..

Read more

I would like to test this with Jest const accept = () => new Promise<boolean>(resolve => { const acceptBtn = document.getElementById(‘accept’); acceptBtn.onclick => () => resolve(true); }) test(‘should return true’, async() => { const spyDocument = jest.spyOn(document, ‘getElementById’); const btn = document.createElement(‘button’); img.id = ‘accept’; img.click = jest.fn(() => Promise.resolve(true)); spyDocument.mockReturnValue(img); const accepted = await ..

Read more

I am trying to build a test package to test an API already deployed, how can I pass the url? Here is an example: const request = require("supertest"); const app = "https://backend.dev.co.mz"; describe("Test the root path", () => { test("It should response the GET method", async () => { const response = await request(app).get("/"); expect(response.statusCode).toBe(200); ..

Read more

Following this documentation: https://react.i18next.com/latest/trans-component This is the piece of code I have written inside my component that works fine on browser. <Trans i18nKey="myKey"> Welcome to <br /> This Space </Trans> Not sure if this is relevant. ButmyKey looks something like this in JSON: myKey: Welcome to <1 /> This Space But due to that my ..

Read more