我的测试组中有两个测试。一个测试使用它,另一个使用测试。它们的工作原理似乎非常相似。它们之间的区别是什么?

describe('updateAll', () => {
  it('no force', () => {
    return updateAll(TableName, ["fileName"], {compandId: "test"})
        .then(updatedItems => {
          let undefinedCount = 0;
          for (let item of updatedItems) {
            undefinedCount += item === undefined ? 1 : 0;
          }
          // console.log("result", result);
          expect(undefinedCount).toBe(updatedItems.length);
        })
  });

  test('force update', () => {
    return updateAll(TableName, ["fileName"], {compandId: "test"}, true)
        .then(updatedItems => {
          let undefinedCount = 0;
          for (let item of updatedItems) {
            undefinedCount += item === undefined ? 1 : 0;
          }
          // console.log("result", result);
          expect(undefinedCount).toBe(0);
        })
  });
});

更新- 2022年11月:

根据Jest的官方API,测试和它似乎是可以互换的。正如这里所描述的@gwildu,出于可读性考虑,您应该选择其中一种。


当前回答

正如其他答案所阐明的那样,它们做的是同样的事情。

我相信提供这两种方式是为了其中任何一种“RSpec”风格的测试,比如:

const myBeverage = {
  delicious: true,
  sour: false,
};

describe('my beverage', () => {
  it('is delicious', () => {
    expect(myBeverage.delicious).toBeTruthy();
  });

  it('is not sour', () => {
    expect(myBeverage.sour).toBeFalsy();
  });
});

或2)“xUnit”风格的测试,比如:

function sum(a, b) {
  return a + b;
}

test('sum adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

文档:

https://jestjs.io/docs/en/api.html#describename-fn https://jestjs.io/docs/en/api.html#testname-fn-timeout

其他回答

正如其他答案所阐明的那样,它们做的是同样的事情。

我相信提供这两种方式是为了其中任何一种“RSpec”风格的测试,比如:

const myBeverage = {
  delicious: true,
  sour: false,
};

describe('my beverage', () => {
  it('is delicious', () => {
    expect(myBeverage.delicious).toBeTruthy();
  });

  it('is not sour', () => {
    expect(myBeverage.sour).toBeFalsy();
  });
});

或2)“xUnit”风格的测试,比如:

function sum(a, b) {
  return a + b;
}

test('sum adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

文档:

https://jestjs.io/docs/en/api.html#describename-fn https://jestjs.io/docs/en/api.html#testname-fn-timeout

Const request = require('supertest'); Const app = require('../app') Const {it, describe} = require('@jest/globals'); Const {sequelize} = require('../models'); Const {hash} = require('../helpers/bcrypt')

beforeAll(async()=>{等待sequize . queryinterface。bulkInsert('Customers',[{用户名:"nikita ",电子邮件:"nikita@mail.com",密码:hash("nikita"), createdAt: new Date(), updatedAt: new Date()}])})

afterAll(async()=>{等待sequel . queryinterface . afterAll)bulkDelete('Customers', null, {truncate: true, cascade: true, restartIdentity: true})})

describe('POST /customers/register', () => { it('should response with status 201', async ()=> { let customer = { username: "hello" , email:"hello@mail.com", password:"hello", } let response = await request(app) .post('/customers/register').send(customer) expect(response.status).toBe(201) // console.log(response.body, 'ini ressss') expect(response.body).toEqual({ message: "Input data Customer succeed", id: expect.any(Number), email: expect.any(String) }) }); it('should response with status 400', async()=>{ let customer = { username: "hello", password:"hello" } let response = await request(app) .post('/customers/register').send(customer) expect(response.status).toBe(400) // console.log(response.body,"<<<"); expect(response.body[0].message).toBe('Please input email') })

Jest文档声明它是test的别名。所以从功能的角度来看它们是完全一样的。它们的存在都是为了让你在考试中写出一个可读的英语句子。

它们是一样的。我使用TypeScript作为编程语言,当我从Jest包源代码中查看定义文件时,从/@types/ Jest /index.d。ts,我可以看到下面的代码。

显然,“test”有很多种不同的名称,你可以使用其中任何一种。

在全部之前声明 var:开玩笑。生命周期; 在 var 之前声明每个:开玩笑。生命周期; 声明 var 毕竟:开玩笑。生命周期; 声明 var 之后每个:开玩笑。生命周期; 声明变量描述:JEST。描述; 声明 var fdescribe: jest。描述; 声明 var xdescribe: jest。描述; 声明变量它:JEST。它; 声明变量适合:开玩笑。它; 声明变量 Xit:开玩笑。它; 声明变量测试:开玩笑。它; 声明 var xtest: jest。它;

`const request = require('supertest');`
`const app =  require('../app')`
`const {it, describe} = require('@jest/globals');`
`const { sequelize, Category, User, News , Customer, Bookmark} = require('../models');`
`const {hash} = require('../helpers/bcrypt');`
`const news = require('../models/news');`
`const {queryInterface} = sequelize`


`beforeAll(async()=>{

    let userData = require("../data/user.json")
    userData.forEach(el => {
        el.password = hash(el.password)
        el.createdAt = new Date()
        el.updatedAt = new Date()
    });`

`afterAll(async ()=>{
    await Bookmark.destroy({
        truncate: true,
        cascade: true,
        restartIdentity: true
    })`

`describe('GET /customers/news', () => {
    it("should response with status 200 1", async () => {
        let response = await request(app)
        .get('/customers/news')
        // .set({access_token})
        // console.log(response.body, "<<<<NEWS NIhH");
        expect(response.status).toBe(200)
        expect(response.body).toBeInstanceOf(Array)
    })`

`it("should response with status 200 2", async()=>{
    let response = await request(app)
    .get('/customers/news?filter=1,2')
    expect(response.status).toBe(200)
    expect(response.body).toBeInstanceOf(Array)
})`