जेस्ट में 'इट ’और' टेस्ट’ में क्या अंतर है?


279

मेरे परीक्षण समूह में मेरे दो परीक्षण हैं। एक परीक्षण का उपयोग करता है, और वे बहुत समान रूप से काम करने लगते हैं। उनके बीच क्या अंतर है?

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);
        })
  });
});

अपडेट करें:

ऐसा लगता है कि testमें है जेस्ट की आधिकारिक एपीआई , लेकिन itनहीं है।


itबस अन्य चौखटों से परिचित और प्रवास के लिए हो सकता है।
एंड्रयू ली

23
इसमें कोई फर्क नही है। प्रलेखन स्पष्ट रूप testसे उपनाम के तहत है it
4

जवाबों:



34

वे एक ही काम करते हैं, लेकिन उनके नाम अलग हैं और परीक्षण के नाम के साथ उनकी बातचीत है।

परीक्षा

आपका लेखन क्या है:

describe('yourModule', () => {
  test('if it does this thing', () => {});
  test('if it does the other thing', () => {});
});

कुछ फेल होने पर आपको क्या मिलता है:

yourModule > if it does this thing

यह

आप क्या लिखते हैं:

describe('yourModule', () => {
  it('should do this thing', () => {});
  it('should do the other thing', () => {});
});

कुछ फेल होने पर आपको क्या मिलता है:

yourModule > should do this thing

तो यह कार्यक्षमता के बारे में नहीं पठनीयता के बारे में है। मेरी राय में, itवास्तव में एक बिंदु है जब यह एक असफल परीक्षा के परिणाम को पढ़ने के लिए आता है जिसे आपने खुद नहीं लिखा है। यह समझने में तेजी से मदद करता है कि परीक्षण किस बारे में है।


4
कुछ भी इसके छोटे के it('does this thing', () => {})बजाय पसंद करते हैंit('should do this thing', () => {}
gwildu

वैकल्पिक रूप से, test('thing should do x')पसंद किया जा सकता है it('Should do X')क्योंकि itअक्सर अस्पष्ट होता है।
मीकाकसाना

21

जैसा कि अन्य उत्तरों ने स्पष्ट किया है, वे एक ही काम करते हैं।

मेरा मानना ​​है कि दोनों को 1 के लिए अनुमति देने की पेशकश की गई है) " 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);
});

डॉक्स:


2

जेस्ट डॉक्स कहते हैं, वे समान हैं: https://jestjs.io/docs/en/api#testname-fn-timeout

परीक्षण (नाम, fn, टाइमआउट)

उपनाम के तहत भी: यह (नाम, एफएन, टाइमआउट)

और वर्णन केवल तब होता है जब आप अपने परीक्षणों को समूहों में व्यवस्थित करना पसंद करते हैं: https://jestjs.io/docs/en/api#describename-fn

वर्णन (नाम, fn)

describe(name, fn)एक ब्लॉक बनाता है जो कई संबंधित परीक्षणों को एक साथ समूहित करता है। उदाहरण के लिए, यदि आपके पास एक MyBeverage ऑब्जेक्ट है जो स्वादिष्ट माना जाता है, लेकिन खट्टा नहीं है, तो आप इसके साथ परीक्षण कर सकते हैं:

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

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

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

यह आवश्यक नहीं है - आप सीधे शीर्ष स्तर पर परीक्षण ब्लॉक लिख सकते हैं। लेकिन यह तब आसान हो सकता है जब आप अपने परीक्षणों को समूहों में व्यवस्थित करना पसंद करते हैं।


-4

जेस्ट ने उल्लेख नहीं किया है कि उनके पास सटीक कार्यक्षमता के लिए दो संस्करण क्यों हैं। मेरा अनुमान है, यह केवल सम्मेलन के लिए है। एकीकरण परीक्षणों के लिए इकाई परीक्षणों के लिए परीक्षण।


-22

वे एक जैसी ही चीज हैं। मैं टाइपस्क्रिप्ट को प्रोग्रामिंग भाषा के रूप में उपयोग कर रहा हूं, और जब मैं /@types/jest/index.d.ts से jest पैकेज स्रोत कोड से परिभाषा फ़ाइल देखता हूं, तो मैं निम्नलिखित कोड देख सकता हूं। जाहिर है कि 'परीक्षण' के कई अलग-अलग नाम हैं, आप उनमें से किसी का भी उपयोग कर सकते हैं।

declare var beforeAll: jest.Lifecycle;
declare var beforeEach: jest.Lifecycle;
declare var afterAll: jest.Lifecycle;
declare var afterEach: jest.Lifecycle;
declare var describe: jest.Describe;
declare var fdescribe: jest.Describe;
declare var xdescribe: jest.Describe;
declare var it: jest.It;
declare var fit: jest.It;
declare var xit: jest.It;
declare var test: jest.It;
declare var xtest: jest.It;


25
आप जो कोड दिखाते हैं, वह इंगित नहीं करता है itऔर testयही बात है। इसका मतलब सिर्फ इतना है कि उनका प्रकार समान है। मुझे नहीं लगता कि beforeAllऔर afterAllवे एक ही चीज हैं भले ही उनका प्रकार एक ही हो।
realUser404

2
xit and xtestपरीक्षण को छोड़ देता है, परीक्षण it, fit, testनिष्पादित करने के लिए होता है। आपके उत्तर के लिए धन्यवाद।
आकाश
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.