-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TDD Style testing to core language stuff
- Loading branch information
1 parent
bcf6ae9
commit 038d14b
Showing
10 changed files
with
6,469 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
|
||
const getGreeting = (isMorning) => { | ||
return isMorning ? "good Morning": "good Evening"; | ||
} | ||
|
||
const result = getGreeting(true); | ||
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const coreLanguageService = { | ||
printHelloWorld: () => { | ||
console.log('Hello, world!'); | ||
}, | ||
printAllDataTypes: () => { | ||
const myNumber = 42; | ||
const myString = "Hello, world!"; | ||
const myBoolean = true; | ||
const myUndefined = undefined; | ||
const myNull = null; | ||
const myObject = { foo: "bar" }; | ||
const mySymbol = Symbol("mySymbol"); | ||
const myBigInt = BigInt(9007199254740991); | ||
console.log( | ||
myNumber, | ||
myString, | ||
myBoolean, | ||
myUndefined, | ||
myNull, | ||
myObject, | ||
mySymbol, | ||
myBigInt | ||
); | ||
}, | ||
getGreeting: (isMorning) => { | ||
return isMorning ? "good Morning": "good Evening"; | ||
}, | ||
printLoop: () => { | ||
for (let i = 1; i <= 10; i++) { | ||
console.log(i); | ||
} | ||
} | ||
} | ||
|
||
module.exports = coreLanguageService; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
|
||
|
||
const coreLanguageService = require("./coreLanguageService"); | ||
|
||
(() => { | ||
const result = 'message'; | ||
console.log(result); | ||
coreLanguageService.printHelloWorld(); | ||
coreLanguageService.printAllDataTypes(); | ||
console.log(coreLanguageService.getGreeting(true)); | ||
coreLanguageService.printLoop(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
const service = require('./coreLanguageService'); | ||
|
||
describe('devguff-nodejs-language-core', () => { | ||
describe("printHelloWorld", () => { | ||
it("should print 'Hello, world!' to the console", () => { | ||
const consoleLogMock = jest.fn(); | ||
console.log = consoleLogMock; | ||
service.printHelloWorld(); | ||
expect(consoleLogMock).toHaveBeenCalledWith("Hello, world!"); | ||
}); | ||
}); | ||
describe("printAllDataTypes", () => { | ||
it("should use all 8 data types in Node.js", () => { | ||
const consoleLogMock = jest.fn(); | ||
console.log = consoleLogMock; | ||
service.printAllDataTypes(); | ||
expect(consoleLogMock).toHaveBeenCalledWith( | ||
42, | ||
"Hello, world!", | ||
true, | ||
undefined, | ||
null, | ||
{ foo: "bar" }, | ||
expect.any(Symbol), | ||
BigInt(9007199254740991) | ||
); | ||
}); | ||
}); | ||
describe("conditional", () => { | ||
it("get greeting should return 'good Morning'", () => { | ||
expect(service.getGreeting(true)).toBe("good Morning"); | ||
}); | ||
it("get greeting should return 'good Evening'", () => { | ||
expect(service.getGreeting(false)).toBe("good Evening"); | ||
}); | ||
}); | ||
describe("printLoop", () => { | ||
it("should print numbers 1 through 10 to the console", () => { | ||
const consoleLogMock = jest.fn(); | ||
console.log = consoleLogMock; | ||
service.printLoop(); | ||
for (let i = 1; i <= 10; i++) { | ||
expect(consoleLogMock).nthCalledWith(i, i); | ||
} | ||
}); | ||
}); | ||
}) | ||
|
Oops, something went wrong.