|
1 |
| -const fs = require('fs'); |
2 |
| -const path = require('path'); |
| 1 | +const { error } = require("console"); |
| 2 | +const fs = require("fs"); |
| 3 | +const path = require("path"); |
3 | 4 | const rewire = require("rewire");
|
4 | 5 |
|
5 | 6 | let _log = console.log;
|
6 |
| -let _buffer = ''; |
7 |
| -global.console.log = console.log = jest.fn((text) => _buffer += text + "\n"); |
| 7 | +let _buffer = ""; |
| 8 | +global.console.log = console.log = jest.fn((text) => (_buffer += text)); |
8 | 9 |
|
9 |
| -const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8'); |
| 10 | +const app_content = fs.readFileSync( |
| 11 | + path.resolve(__dirname, "./app.js"), |
| 12 | + "utf8" |
| 13 | +); |
10 | 14 |
|
11 |
| -test('You have to use the console.log function to print the correct output', function () { |
12 |
| - const app = require('./app.js'); |
13 |
| - expect(console.log.mock.calls.length > 0).toBe(true); |
| 15 | +test("You have to use the console.log function to print the correct output", function () { |
| 16 | + const app = require("./app.js"); |
| 17 | + expect(console.log.mock.calls.length > 0).toBe(true); |
14 | 18 | });
|
15 | 19 |
|
16 |
| -test('The output in the console should match the one in the instructions', function () { |
17 |
| - const _app = rewire('./app.js'); |
18 |
| - let _tasks = [ |
19 |
| - { label: 'Eat my lunch', done: true }, |
20 |
| - { label: 'Make the bed', done: false }, |
21 |
| - { label: 'Have some fun', done: false }, |
22 |
| - { label: 'Finish the replits', done: false }, |
23 |
| - { label: 'Replit the finishes', done: true }, |
24 |
| - { label: 'Ask for a raise', done: false }, |
25 |
| - { label: 'Read a book', done: true }, |
26 |
| - { label: 'Make a trip', done: false } |
27 |
| - ]; |
28 |
| - let _test = _tasks.filter(item => item.done === true) |
29 |
| - |
30 |
| - expect(_buffer).toMatch(_test.map(n => n).join(",")); |
31 |
| - // expect(_buffer).toMatch(_test.map(n => n).join("\n")); |
32 |
| - |
33 |
| - }); |
34 |
| - |
35 |
| - |
36 |
| - |
37 |
| - |
| 20 | +test("The output in the console should match the one in the instructions", function () { |
| 21 | + const _app = rewire("./app.js"); |
| 22 | + let _tasks = [ |
| 23 | + { label: "Eat my lunch", done: true }, |
| 24 | + { label: "Make the bed", done: false }, |
| 25 | + { label: "Have some fun", done: false }, |
| 26 | + { label: "Finish the replits", done: false }, |
| 27 | + { label: "Replit the finishes", done: true }, |
| 28 | + { label: "Ask for a raise", done: false }, |
| 29 | + { label: "Read a book", done: true }, |
| 30 | + { label: "Make a trip", done: false }, |
| 31 | + ]; |
| 32 | + let _test = _tasks.filter((item) => item.done === true); |
| 33 | + |
| 34 | + expect(_buffer.length).toBe( |
| 35 | + [ |
| 36 | + { label: "Eat my lunch", done: true }, |
| 37 | + { label: "Finish my exercises", done: true }, |
| 38 | + { label: "Read a book", done: true }, |
| 39 | + ].join("\n").length |
| 40 | + ); |
| 41 | +}); |
0 commit comments