- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近完成了一项编码测试,该测试要求我确保我的所有代码都使用 Node (npm 测试)通过。在九个测试中,我全部都失败了,尽管我已经在我自己的环境中成功地测试了我的代码。对于每个问题,测试都表明我的代码返回“未定义”,我认为这可能更像是一个 git/github 混淆问题,而不是错误的代码。我在 git/github 上学了一整门课,还是找不到问题!
我已经完成了测试说明中列出的所有步骤(直到第 5 步,因为我无法通过他们的测试!): https://github.com/LambdaSchool/Lambda-Challenge
这是我的代码:
/*
Work through the problems in this file. As you work through each
problem periodically run: npm test
Your function name and the string must match the instructions exactly
otherwise the tests will fail.
After writing your function uncomment the matching function reference
at the bottom of the file.
*/
/* 1. Write a function called helloWorld that returns the string
'Hello World!'. */
function helloWorld() {
return 'Hello World!';
}
/*
2. Write a function called lambdaSchool that has a single parameter
called num.
num will be a positive integer.
If num is divisible by 3 return the string 'Lambda'
If num is divisible by 5 return the string 'School'
If num is divisible by 3 AND 5 return the string 'Lambda School' (notice the space)
If num is NOT divisible by 3 or 5 then return num.
Example:
lambdaSchool(15); // returns 'Lambda School'
lambdaSchool(8); // returns 8
*/
function lambdaSchool(num) {
if (num % 5 === 0 && num % 3 === 0) {
return "Lambda School";
} else if (num % 5 === 0) {
return "School";
} else if (num % 3 === 0) {
return "Lambda";
} else {
return num;
}
}
/*
3. Write a function called longestString that has a single parameter
called strs.
strs will be an array of strings.
Return the longest string that is in strs.
If there is a tie for the longest string then return the one that
occurs first.
Example:
longestString(['hi', 'hello', 'ni hao', 'guten tag']); //
returns 'guten tag'
longestString(['JavaScript', 'HTML', 'CSS']); // returns
'JavaScript'
*/
var longest = '';
function longestString(strs) {
for (i = 0; i < strs.length; i++) {
if (strs[i].length > longest.length) {
longest = strs[i];
}
}
return longest;
}
/*
4. Write a function called computeUserAverageAge that has a single
parameter called users
users is an array of user objects.
Each user object has a property called age that is a number.
Compute the average age of all user objects in the users array.
Round off the decimals if needed and return the number.
Example:
const users = [{
name: 'Brendan Eich',
age: 56,
}, {
name: 'Linus Torvalds',
age: 48,
}, {
name: 'Margaret Hamilton',
age: 81,
}];
computeUserAverageAge(users); // returns 62 (This number is
rounded up from 61.6666)
*/
function computeUserAverageAge(users) {
return Math.round(users.reduce((acc, obj) => acc + obj.age, 0) /
users.length);
};
module.exports = {
helloWorld,
lambdaSchool,
longestString,
computeUserAverageAge
};
这是 Node 测试(npm 测试)的结果:
FAIL ./assessment.test.js
Lambda School Precourse Assessment
helloWorld
✕ should return a string (10ms)
✕ should return the string 'Hello World!' (1ms)
lambdaSchool
✕ should return 'Lambda' for a number divisible by 3
✕ should return 'School' for a number divisible by 5 (1ms)
✕ should return 'Lambda School' for a number divisible by 3 and 5
longestString
✕ should return the longest string in the array
✕ should return the first longest string if there is a tie (1ms)
computeUserAverageAge
✕ should return the average age of the users
✕ should round the average before returning it (1ms)
● Lambda School Precourse Assessment › helloWorld › should return
a
string
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"string"
Received:
"undefined"
9 | describe('helloWorld', () => {
10 | it('should return a string', () => {
> 11 | expect(typeof helloWorld()).toBe('string');
12 | });
13 | it('should return the string \'Hello World!\'', () => {
14 | expect(helloWorld()).toBe('Hello World!');
at Object.it (assessment.test.js:11:35)
● Lambda School Precourse Assessment › helloWorld › should return
the
string 'Hello World!'
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"Hello World!"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but received undefined.
12 | });
13 | it('should return the string \'Hello World!\'', () => {
> 14 | expect(helloWorld()).toBe('Hello World!');
15 | });
16 | });
17 |
at Object.it (assessment.test.js:14:28)
● Lambda School Precourse Assessment › lambdaSchool › should
return 'Lambda' for a number divisible by 3
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"Lambda"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but
received undefined.
18 | describe('lambdaSchool', () => {
19 | it('should return \'Lambda\' for a number divisible by 3',
() => {
> 20 | expect(lambdaSchool(12)).toBe('Lambda');
21 | expect(lambdaSchool(63)).toBe('Lambda');
22 | expect(lambdaSchool(999)).toBe('Lambda');
23 | });
at Object.it (assessment.test.js:20:32)
● Lambda School Precourse Assessment › lambdaSchool › should
return
'School' for a number divisible by 5
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"School"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but
received undefined.
23 | });
24 | it('should return \'School\' for a number divisible by 5',
() => {
> 25 | expect(lambdaSchool(10)).toBe('School');
26 | expect(lambdaSchool(155)).toBe('School');
27 | expect(lambdaSchool(1000)).toBe('School');
28 | });
at Object.it (assessment.test.js:25:32)
● Lambda School Precourse Assessment › lambdaSchool › should
return
'Lambda School' for a number divisible by 3 and 5
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"Lambda School"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but
received undefined.
28 | });
29 | it('should return \'Lambda School\' for a number divisible
by 3 and 5', () => {
> 30 | expect(lambdaSchool(15)).toBe('Lambda School');
31 | expect(lambdaSchool(30)).toBe('Lambda School');
32 | expect(lambdaSchool(180)).toBe('Lambda School');
33 | });
at Object.it (assessment.test.js:30:32)
● Lambda School Precourse Assessment › longestString › should return
the
longest string in the array
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"function"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but
received undefined.
36 | describe('longestString', () => {
37 | it('should return the longest string in the array', () => {
> 38 | expect(longestString(['array', 'object',
'function'])).toBe('function');
39 | expect(longestString(['C++', 'JavaScript',
'Python'])).toBe('JavaScript');
40 | });
41 | it('should return the first longest string if there is a
tie', () => {
at Object.it (assessment.test.js:38:62)
● Lambda School Precourse Assessment › longestString › should return
the
first longest string if there is a tie
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"C++"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but
received undefined.
40 | });
41 | it('should return the first longest string if there is a
tie', () => {
> 42 | expect(longestString(['C++', 'CSS', 'JWT'])).toBe('C++');
43 | });
44 | });
45 |
at Object.it (assessment.test.js:42:52)
● Lambda School Precourse Assessment › computeUserAverageAge › should
return the average age of the users
expect(received).toBe(expected) // Object.is equality
Expected value to be:
62
Received:
undefined
Difference:
Comparing two different types of values. Expected number but
received undefined.
66 | }];
67 | it('should return the average age of the users', () => {
> 68 | expect(computeUserAverageAge(authors)).toBe(62);
69 | });
70 | it('should round the average before returning it', () => {
71 |
expect(computeUserAverageAge(computerScientists)).toBe(62);
at Object.it (assessment.test.js:68:46)
● Lambda School Precourse Assessment › computeUserAverageAge › should
round the average before returning it
expect(received).toBe(expected) // Object.is equality
Expected value to be:
62
Received:
undefined
Difference:
Comparing two different types of values. Expected number but
received undefined.
69 | });
70 | it('should round the average before returning it', () => {
> 71 |
expect(computeUserAverageAge(computerScientists)).toBe(62);
72 | });
73 | });
74 | });
at Object.it (assessment.test.js:71:57)
Test Suites: 1 failed, 1 total
Tests: 9 failed, 9 total
Snapshots: 0 total
Time: 0.613s, estimated 1s
Ran all test suites matching /assessment.test.js/i.
npm ERR! Test failed. See above for more details.
非常感谢您的时间和耐心!
最佳答案
在您进行编辑后,您是否保存了您的代码?如果您输入以下 git commit -a -m 'My changes to the code'。然后 git push。
关于javascript - 与 Git/GitHub 协作使用 Node 测试代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50825426/
你好 StackOverflow。 我在 Github 上遇到了一个奇怪的错误。 存储库 Link 我在 4 个月前创建了一个存储库。并且只向该存储库添加了 2 个贡献者。 • 我没有再添加贡献者但是
我已经配置了 Jenkins Github 拉取请求构建器插件来构建我机构成员提出的每个拉取请求。它就像一个魅力。 但是,构建并没有像在这个不错的 post 中显示的那样将构建状态报告回 github
我只是想知道在任何 GitHub 源代码查看页面上可以查看多少个字符而不会溢出(水平滚动)。 最佳答案 在 OS X v10.9 (小牛队): 谷歌浏览器:125 火狐:122 Safari :121
我一直在寻找可以进入 .github 的事物的零碎示例。 GitHub 存储库上的目录。 我可以看到它用于 GitHub 操作和工作流以及拉取请求和问题模板,但我看不到一个页面,其中概述了您可以在理想
尝试运行 --is-bare-repository 命令,但意识到在我的克隆副本上运行它是不正确的。有没有办法在实际的 GitHub 存储库上使用相同的命令?存储库也没有显示 .git 文件。请原谅我
我正在使用 github 页面和 jekyll 创建一个博客。我想知道是否有一种方法可以将 github 文件(即存储库中的文件)中的代码片段嵌入到博客文章中。我可以在此页面上找到有关嵌入要点的解决方
我在 GitHub 存储库中有一个文件,需要通过运行命令偶尔更新。 作为 GitHub Workflows 的一部分,我想让一个机器人运行一个命令,并查看它是否在 repo 上创建了一个差异,如果是,
尝试从 Github 桌面应用程序发布到 github.com 时出现以下错误。 GitHub Desktop was unable to store the account token in the
类似于Desktop notifications from GitHub (从 10 年前开始)但提出了一个稍微不同的问题 - GitHub 是否支持 web notifications ?我想知道关
我想使用 semantic-release 在 Github 版本上发布整个目录(构建目录),但不幸的是它将每个构建文件作为单个 Assets 发布。 用于复制: 我正在使用 Vue CLI 生成一个
这让我发疯,我知道这听起来像是一个愚蠢的问题,但我已经为此苦苦挣扎了 2 天。我刚刚完成了 Visual Code 的编码,我想将它推送到 github 上。所以我创建了一个名为 mern-maps
在 GitHub 上,一个用户可以属于多个组织。一个存储库是否也可以成为多个组织的一部分? 最佳答案 根据 this blog post by GitHub , 一个仓库只能属于一个组织。 Creat
在 GitHub 操作中,我使用脚本创建了一个文件。然后我可以使用 git 创建一个分支,添加文件,提交文件并将分支推送到 repo。全部使用 git。 然后我想从我的操作中创建一个 PR,所以我使用
在 GitHub 中,当我转到:[Insights] - [Networks] 时,我看到我的分支有不同的颜色。有些在 blue , 其他人在 green .我找不到解释。 有谁知道不同颜色是什么意思
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我只是在尝试 GitHub。 为什么有些提交显示为“一天前在 GitHub 上提交”而其他提交显示为“一天前提交”? 例如这里: https://github.com/apple/swift/comm
有没有办法更改 Github 上的配色方案以进行语法高亮显示?我已经进行了基本搜索,但找不到答案。 最佳答案 目前没有办法改变服务器端的配色方案。 github.com 的几个用户已经要求 自定义语法
Github 上关闭的拉取请求是否意味着拉取请求未合并? 如果没有,有没有办法确定已关闭的拉取请求是否已合并? 谢谢。 最佳答案 If no, is there a way I can determi
不确定这是否与主题无关,但我真的很好奇这种类型的图表是否有名称以及如何创建。 像这样:https://help.github.com/articles/viewing-contributions-on
GitHub 中合作者和贡献者的拉取请求有什么区别?我没有发现合作者有任何特殊特权。 最佳答案 合作者对贡献者的一项特权是......他们(合作者)可以直接推送到您的存储库(因为您拥有 added t
我是一名优秀的程序员,十分优秀!