CodingTrain / CodingTrain/Toy-Neural-Network-JS

Custom test without node using pure javascript

Đang mở
#76 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
437
Fork
242
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hey, I just tried to create my own test function which kind of similar to the Jest library.
Have been testing for 5 statements below and yet to find any failure.
But for now, it only have 2 functional tests which is expect(value).toBe(other) and expect(value).toEqual(something).

Let me see what do you guys think about this kind of stuff. Is it worth it?

Below is the implementation of the tests

```
function check(current,other){
if(typeof other !== 'object' && typeof current !== 'object') return current === other;
let equal = false;
for(let prop in other){
if(current[prop] === undefined) throw new Error("FAILED");
equal = equal || check(current[prop],other[prop]);
}
if(!equal) throw new Error("FAILED");
return equal;
}

function test(comment,callback){
let error;
try{
//execute the tests;
callback();
}catch(e){
// Get the result whether it passed or failed
error = e.message;
}
console.log(comment,error === "FAILED" ? "FAILED" : "PASSED");
}

function expect(value){
this.toBe = function(other){
if(value !== other) throw new Error("FAILED");
}
this.toEqual = function(something){
check(value,something);
}
return this;
}

// The tests start HERE

test('Is 2+2 be 4?',() => {
expect(2 + 2).toBe(4); // returns : Is 2+2 be 4? PASSED
});

test('Is 2+3 be 4?',() => {
expect(2 + 3).toBe(4); // returns : Is 2+3 be 4? FAILED
});

test('Is {value:3*3} equal {value:9}?',() => {
expect({value:3*3}).toEqual({value:9}); // returns : Is {value:3*3} equal {value:9}? PASSED
});

test('Is {value:2*3} equal {value:9}?',() => {
expect({value:2*3}).toEqual({value:9}); // returns : Is {value:2*3} equal {value:9}? FAILED
});

test('Is {value:{arr:[6]}} equal {value:9}?',() => {
expect({value:{arr:[6]}}).toEqual({value:9}); // Is {value:{arr:[6]}} equal {value:9}? FAILED
});
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Issue chứa một triển khai hàm kiểm thử JavaScript inline, nhưng không nêu tên tệp, kiểm thử hoặc điểm vào nào của repository. Trước tiên cần làm rõ liệu việc này có nên trở thành một tính năng của dự án hay không và xác định phạm vi của nó; để hoàn thành sẽ cần có một vị trí triển khai được thống nhất và các kiểm thử cho hành vi được đề xuất.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
testing
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
20/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.