scrimba
Unit Testing
Skipping and Focusing Introduction
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Skipping and Focusing Introduction
AboutCommentsNotes
Skipping and Focusing Introduction
Expand for more info
main.js
run
preview
console
// Unit Testing: Skipping and Focusing Introduction

// Test Suite
describe(`${User.name} Class`, () => {
let model;

beforeEach(() => {
model = new User();
});

describe('default values', () => {
it('first name defaults to empty', () => {
// assert
expect(model.firstName).toBe('');
});

it('last name defaults to empty', () => {
// assert
expect(model.lastName).toBe('');
});

it('middle name defaults to empty', () => {
// assert
expect(model.middleName).toBe('');
});
});

describe('full name', () => {
beforeEach(() => {
model = new User({ firstName: 'Dylan', lastName: 'Israel' });
});

it('middle initial when middleName is defined with first and last', () => {
// arrange
model.middleName = 'Christopher';

// act
const result = model.fullName;

// assert
expect(result).toBe(`${model.firstName} ${model.middleName[0]}. ${model.lastName}`);
});

it('when no middle name return just first and last', () => {
// arrange
model.middleName = '';

// act
const result = model.fullName;

// assert
expect(result).toBe(`${model.firstName} ${model.lastName}`);
});
});
});
Console
/index.html
-1:47