Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Custom test without node using pure javascript

未关闭
#76 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
20/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
javascript
领域
testing

调研方向

该 issue 包含一个内联的 JavaScript 测试函数实现,但没有指明任何 repository 文件、测试或入口点。首先需要明确这是否应成为项目功能,并定义其范围;要完成此工作,需要就实现位置达成一致,并为提议的行为编写测试。

由索引模型根据 Issue 内容生成。

描述

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
});
主要语言
JavaScript
星标
437
派生
242
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CodingTrain/Toy-Neural-Network-JS 的其他 Issue

查看 CodingTrain/Toy-Neural-Network-JS 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。