Skip to content

Commit

Permalink
chore: cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Oct 23, 2024
1 parent b56293a commit c9e455b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('color attribute', () => {
}
});

it('sets font color', done => {
it('sets font color', async () => {
let model = {color: 'green'};

component = StageComponent
Expand All @@ -24,13 +24,8 @@ describe('color attribute', () => {
.inView('<p color.bind="color"></p>')
.boundTo(model);

component.create(bootstrap).then(() => {
const view = component.element;
expect(view.style.color).toBe('green');
done();
}).catch(e => {
fail(e);
done();
});
await component.create(bootstrap);
const view = component.element;
expect(view.style.color).toBe('green');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('primaryClick binding behavior', () => {
}
});

it('sets font color', done => {
it('sets font color', async () => {
let hitted = false;
function hit() { hitted = true; }

Expand All @@ -45,19 +45,16 @@ describe('primaryClick binding behavior', () => {
.boundTo(model);

let view;
component.create(bootstrap).then(() => {
view = component.element;
fireEvent(view, 'click', {button: 0});
}).then(delay).then(() => {
expect(hitted).toBe(true);
hitted = false;
fireEvent(view, 'click', {button: 1});
}).then(delay).then(() => {
expect(hitted).toBe(false);
done();
}).catch(e => {
fail(e);
done();
});
await component.create(bootstrap);
view = component.element;
fireEvent(view, 'click', {button: 0});
await delay();

expect(hitted).toBe(true);
hitted = false;
fireEvent(view, 'click', {button: 1});
await delay();

expect(hitted).toBe(false);
});
});
13 changes: 4 additions & 9 deletions plugin/test__if_karma_or_jest/unit/elements/hello-world.spec.ext
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('hello-world element', () => {
}
});

it('says hello world with message', done => {
it('says hello world with message', async () => {
let model = {message: 'from me'};

component = StageComponent
Expand All @@ -24,13 +24,8 @@ describe('hello-world element', () => {
.inView('<hello-world message.bind="message"></hello-world>')
.boundTo(model);

component.create(bootstrap).then(() => {
const view = component.element;
expect(view.textContent.trim()).toBe('Hello world from me');
done();
}).catch(e => {
fail(e);
done();
});
await component.create(bootstrap);
const view = component.element;
expect(view.textContent.trim()).toBe('Hello world from me');
});
});
13 changes: 4 additions & 9 deletions scaffold-minimum/test__if_karma_or_jest/unit/app.spec.ext
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ describe('Stage App Component', () => {

afterEach(() => component.dispose());

it('should render message', done => {
component.create(bootstrap).then(() => {
const view = component.element;
expect(view.textContent.trim()).toBe('Hello World!');
done();
}).catch(e => {
fail(e);
done();
});
it('should render message', async () => {
await component.create(bootstrap);
const view = component.element;
expect(view.textContent.trim()).toBe('Hello World!');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@ class HttpStub {
});
}

configure(func) {
}
configure(func) { /**/ }
}

describe('the Users module', () => {
it('sets fetch response to users', (done) => {
it('sets fetch response to users', async () => {
var http = new HttpStub();
var sut = new Users(http);
var itemStubs = [1];
var itemFake = [2];

http.itemStub = itemStubs;
sut.activate().then(() => {
expect(sut.users).toBe(itemStubs);
expect(sut.users).not.toBe(itemFake);
done();
});
await sut.activate();
expect(sut.users).toBe(itemStubs);
expect(sut.users).not.toBe(itemFake);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {HttpClient} from 'aurelia-fetch-client';

class HttpStub {
items: any[];

fetch(url) {
return new Promise(resolve => {
resolve({ json: () => this.items });
});
}

configure(func) { /**/ }
}

Expand All @@ -18,19 +18,16 @@ function createHttpStub(): any {
}

describe('the Users module', () => {
it('sets fetch response to users', async () => {
const http = createHttpStub();
const sut = new Users(<HttpClient>http);
const itemStubs = [1];
const itemFake = [2];

it('sets fetch response to users', (done) => {
const http = createHttpStub(),
sut = new Users(<HttpClient>http),
itemStubs = [1],
itemFake = [2];

http.items = itemStubs;

sut.activate().then(() => {
expect(sut.users).toBe(itemStubs);
expect(sut.users).not.toBe(itemFake);
done();
});

await sut.activate();
expect(sut.users).toBe(itemStubs);
expect(sut.users).not.toBe(itemFake);
});
});

0 comments on commit c9e455b

Please sign in to comment.