Skip to content

Instantly share code, notes, and snippets.

@alex-hall
Created November 2, 2018 17:59
Show Gist options
  • Save alex-hall/963f966febab340d3d949dc4b6192dcf to your computer and use it in GitHub Desktop.
Save alex-hall/963f966febab340d3d949dc4b6192dcf to your computer and use it in GitHub Desktop.
lab-1-solution
describe('The Basics', () => {
it('works the way you would expect', () => {
expect("Hello world. Replace me with the number one for your first passing test!").toEqual(1)
})
describe("Truthy v Falsy", () => {
beforeAll(() => {
//TODO: Go Read: https://www.sitepoint.com/javascript-truthy-falsy/
})
it('will all work if you understand the concepts!', () => {
expect("What are things that are truthy?").toBeTruthy()
expect(null).toBeFalsy()
expect(1).toBeTruthy()
expect(0).toBeFalsy()
expect('false').toBeTruthy()
expect(undefined).toBeFalsy()
expect(() => {
}).toBeTruthy()
})
})
describe('Math', () => {
it('will test your math skills', () => {
expect(1 + 1).toEqual(2)
expect(100 + 100).toEqual(200)
expect(2 ** 3).toEqual(8)
})
})
describe('Arrays && Aggregates', () => {
it('shouldnt make you feel nervous', () => {
expect([1, 2, 3]).toContain(2)
expect([1, 2, 3].map(n => n * 2)).toEqual([2, 4, 6])
})
})
describe('Objects', () => {
it('should help solve difficult problems', () => {
const objectUnderTest = {
interestingProperty: 'The Answer to the first test!',
methodUnderTest: () => 'I want to equal BANANA!'
}
expect(objectUnderTest.interestingProperty).toEqual("The Answer to the first test!")
expect(objectUnderTest.methodUnderTest()).toEqual("I want to equal BANANA!")
expect(typeof objectUnderTest).toEqual('object')
})
})
})
//Pay no attention to the javascript behind the curtain!
expect.extend({
toBe___: () => ({
pass: false,
message: () => 'Replace me with either a toBeTruthy() matcher or toBeFalsy() matcher'
})
})
//Don't change me, change the test!
const ___ = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment