-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fe87a6
commit ba7e306
Showing
4 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* beforeAll(fn, timeout) | ||
* beforeEach(fn, timeout) | ||
*/ | ||
|
||
function check() { | ||
return 1; | ||
} | ||
|
||
beforeAll(() => { | ||
/** | ||
* Used with | ||
* 1- Connect to database. | ||
* 2- Empty testing table | ||
* 3- Add dummy data for testing | ||
* 4- Prepare everything before testing | ||
*/ | ||
expect(check()).toBe(1); | ||
}); | ||
|
||
afterAll(() => { | ||
/** | ||
* Used with | ||
* 1- Clean database | ||
* 2- Clean cache | ||
*/ | ||
expect(check()).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const allData = require("../all"); | ||
|
||
test("Check if array contain 6 elements", () => { | ||
expect(allData.length).toBe(5); | ||
}); | ||
|
||
test("Check if array contain 6 elements but with different method", () => { | ||
expect(allData).toHaveLength(5); | ||
}); | ||
|
||
test("Check if array contain number 4", () => { | ||
expect(allData).toContain(4); | ||
}); | ||
|
||
test("Check if array contain only number [1st method]", () => { | ||
for (let i = 0; i < allData.length; i++) { | ||
expect(isNaN(allData[i])).toBe(false); | ||
} | ||
}); | ||
|
||
test("Check if array contain only number [2nd method]", () => { | ||
for (let i = 0; i < allData.length; i++) { | ||
expect(isNaN(allData[i])).toBeFalsy(); | ||
} | ||
}); | ||
|
||
test("Check if array contain only number [3rd method]", () => { | ||
for (let i = 0; i < allData.length; i++) { | ||
expect(isNaN(allData[i])).not.toBeTruthy(); | ||
} | ||
}); | ||
|
||
test("Check if array first element is larger than 0", () => { | ||
expect(allData[0]).toBeGreaterThanOrEqual(1); | ||
}); | ||
|
||
test("Check if array first element is less than 10", () => { | ||
expect(allData[0]).toBeLessThanOrEqual(10); | ||
}); | ||
|
||
test("Check for undefined", () => { | ||
expect(allData[10]).toBeUndefined(); | ||
}); | ||
|
||
test("Check for substring inside string by RegExp", () => { | ||
let myString = "I love Jest"; | ||
expect(myString).toMatch(/Jest/); | ||
}); | ||
|
||
test("Check for property age", () => { | ||
let myObject = { | ||
name: "Ahmed", | ||
age: 30, | ||
}; | ||
expect(myObject).toHaveProperty("age"); | ||
}); | ||
|
||
test("Check for property age that have value of 30", () => { | ||
let myObject = { | ||
name: "Ahmed", | ||
age: 30, | ||
}; | ||
expect(myObject).toHaveProperty("age", 30); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const allData = [1, 2, 3, 4, 5]; | ||
|
||
module.exports = allData; |