Any file names, that should start with anything but must end with .test.js or .spec.js files are considered as a test file. (or)
All the files within the test folder are considered test files. Note: there are many ways to represent a file as a test file.
Basic example code:
function sortedDataByAge(){
const obj = [
{ name: "shivaji", age: 23 },
{ name: "vyshnavi", age: 21 },
{ name: "Ravi", age: 50 },
];
return obj.sort((a, b) => a.age - b.age);
}
test("Testing the sorted feature", ()=>{
const sortedDataByAge = sortedDataByAge()
expect(sortedDataByAge[0].name).toBe("vyshnavi")
})
Methods: toBe() not.toBe(undefined) toBeUndefined(): it passes for an undefined value. not.toBeUndefined(): it fails for an undefined value.
Note: You write a test case but you can't do any Assertions and then your test cases are always passed.
test("Testing the sorted feature", ()=>{
// No Assertion
})
Automatically Reload: "watch:test" : "jest --watch"
Component Testing: Steps:
create test case: you can create test cases using test or it methods. syntax:
test("test case description", ()=>{
//test case logic
})
//OR
it("test case description", ()=>{
//test case logic
})
describe: