Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions exercises/21.2-Filter-done-tasks/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
let tasks = [
{ label: 'Eat my lunch', done: true },
{ label: 'Make the bed', done: false },
{ label: 'Have some fun', done: false },
{ label: 'Finish the replits', done: false },
{ label: 'Finish my exercises', done: true },
{ label: 'Ask for a raise', done: false },
{ label: 'Read a book', done: true },
{ label: 'Make a trip', done: false }
{ label: "Eat my lunch", done: true },
{ label: "Make the bed", done: false },
{ label: "Have some fun", done: false },
{ label: "Finish the replits", done: false },
{ label: "Finish my exercises", done: true },
{ label: "Ask for a raise", done: false },
{ label: "Read a book", done: true },
{ label: "Make a trip", done: false },
];

// Your code here
64 changes: 34 additions & 30 deletions exercises/21.2-Filter-done-tasks/test.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
const fs = require('fs');
const path = require('path');
const { error } = require("console");
const fs = require("fs");
const path = require("path");
const rewire = require("rewire");

let _log = console.log;
let _buffer = '';
global.console.log = console.log = jest.fn((text) => _buffer += text + "\n");
let _buffer = "";
global.console.log = console.log = jest.fn((text) => (_buffer += text));

const app_content = fs.readFileSync(path.resolve(__dirname, './app.js'), 'utf8');
const app_content = fs.readFileSync(
path.resolve(__dirname, "./app.js"),
"utf8"
);

test('You have to use the console.log function to print the correct output', function () {
const app = require('./app.js');
expect(console.log.mock.calls.length > 0).toBe(true);
test("You have to use the console.log function to print the correct output", function () {
const app = require("./app.js");
expect(console.log.mock.calls.length > 0).toBe(true);
});

test('The output in the console should match the one in the instructions', function () {
const _app = rewire('./app.js');
let _tasks = [
{ label: 'Eat my lunch', done: true },
{ label: 'Make the bed', done: false },
{ label: 'Have some fun', done: false },
{ label: 'Finish the replits', done: false },
{ label: 'Replit the finishes', done: true },
{ label: 'Ask for a raise', done: false },
{ label: 'Read a book', done: true },
{ label: 'Make a trip', done: false }
];
let _test = _tasks.filter(item => item.done === true)
expect(_buffer).toMatch(_test.map(n => n).join(","));
// expect(_buffer).toMatch(_test.map(n => n).join("\n"));

});




test("The output in the console should match the one in the instructions", function () {
const _app = rewire("./app.js");
let _tasks = [
{ label: "Eat my lunch", done: true },
{ label: "Make the bed", done: false },
{ label: "Have some fun", done: false },
{ label: "Finish the replits", done: false },
{ label: "Replit the finishes", done: true },
{ label: "Ask for a raise", done: false },
{ label: "Read a book", done: true },
{ label: "Make a trip", done: false },
];
let _test = _tasks.filter((item) => item.done === true);

expect(_buffer.length).toBe(
[
{ label: "Eat my lunch", done: true },
{ label: "Finish my exercises", done: true },
{ label: "Read a book", done: true },
].join("\n").length
);
});