Тестирование кода с узлом в сотрудничестве с Git / GitHub - PullRequest
0 голосов
/ 12 июня 2018

Я недавно закончил тестирование кода, которое требует от меня проверки того, что весь мой код проходит с использованием узла (тест 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
};

, а вот результаты теста узла (теста 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.

Я не могу выразить благодарность за ваши словавремя и терпение!

1 Ответ

0 голосов
/ 12 июня 2018

После того, как вы внесли свои изменения, вы сохранили свой код?Если вы, наберите следующий git commit -a -m «Мои изменения в коде».Тогда нажми толчок.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...