pass assert into tests

pull/31/head
Rich-Harris 8 years ago
parent c79b38ff6a
commit 1b8c2ff4f3

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: `<div style="color: red;">red</div>`,
test ( component, target ) {
test ( assert, component, target ) {
const div = target.querySelector( 'div' );
assert.equal( div.style.color, 'red' );

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: `<textarea readonly=""></textarea>`,
test ( component, target ) {
test ( assert, component, target ) {
const textarea = target.querySelector( 'textarea' );
assert.ok( textarea.readOnly );
}

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: '<!--#if visible-->',
test ( component, target, window ) {
test ( assert, component, target, window ) {
component.set({ visible: true });
assert.equal( component.refs.input, window.document.activeElement );
}

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
data: {
items: [
@ -9,7 +7,7 @@ export default {
]
},
html: `<div><input type="checkbox"><p>one</p></div><div><input type="checkbox"><p>two</p></div><div><input type="checkbox"><p>three</p></div><!--#each items-->\n\n<p>1 completed</p>`,
test ( component, target, window ) {
test ( assert, component, target, window ) {
const inputs = [ ...target.querySelectorAll( 'input' ) ];
assert.ok( inputs[0].checked );

@ -1,11 +1,9 @@
import * as assert from 'assert';
export default {
data: {
foo: true
},
html: `<input type="checkbox">\n<p>true</p>`,
test ( component, target, window ) {
test ( assert, component, target, window ) {
const input = target.querySelector( 'input' );
assert.equal( input.checked, true );

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
data: {
items: [
@ -9,7 +7,7 @@ export default {
]
},
html: `<div><input><p>one</p></div><div><input><p>two</p></div><div><input><p>three</p></div><!--#each items-->`,
test ( component, target, window ) {
test ( assert, component, target, window ) {
const inputs = [ ...target.querySelectorAll( 'input' ) ];
const items = component.get( 'items' );
const event = new window.Event( 'input' );

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
data: {
items: [
@ -9,7 +7,7 @@ export default {
]
},
html: `<div><input><p>one</p></div><div><input><p>two</p></div><div><input><p>three</p></div><!--#each items-->`,
test ( component, target, window ) {
test ( assert, component, target, window ) {
const inputs = [ ...target.querySelectorAll( 'input' ) ];
assert.equal( inputs[0].value, 'one' );

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
data: {
user: {
@ -7,7 +5,7 @@ export default {
}
},
html: `<input>\n<p>hello alice</p>`,
test ( component, target, window ) {
test ( assert, component, target, window ) {
const input = target.querySelector( 'input' );
assert.equal( input.value, 'alice' );

@ -1,11 +1,9 @@
import * as assert from 'assert';
export default {
data: {
name: 'world'
},
html: `<input>\n<p>hello world</p>`,
test ( component, target, window ) {
test ( assert, component, target, window ) {
const input = target.querySelector( 'input' );
assert.equal( input.value, 'world' );

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
data: {
bar: 'lol',
@ -7,7 +5,7 @@ export default {
compound: 'piece of'
},
html: `<div><p>foo: lol</p>\n<p>baz: 42 (number)</p>\n<p>qux: this is a piece of string</p></div>`,
test ( component, target ) {
test ( assert, component, target ) {
component.set({
bar: 'wut',
x: 3,

@ -1,7 +1,5 @@
import * as assert from 'assert';
export default {
test ( component, target, window ) {
test ( assert, component, target, window ) {
const buttons = target.querySelectorAll( 'button' );
const click = new window.MouseEvent( 'click' );

@ -1,11 +1,9 @@
import * as assert from 'assert';
export default {
data: {
visible: true
},
html: '<div><!--#if visible--><p>i am a widget</p></div>', // TODO comment should follow component...
test ( component ) {
test ( assert, component ) {
let count = 0;
component.on( 'widgetTornDown', function () {

@ -1,9 +1,8 @@
import * as assert from 'assert';
import Widget from './Widget.html';
export default {
html: '<div><p>i am a widget</p></div>',
test ( component ) {
test ( assert, component ) {
const widget = component.refs.widget;
assert.ok( widget instanceof Widget );
}

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: '<p>1 + 2 = 3</p>\n<p>3 * 3 = 9</p>',
test ( component, target ) {
test ( assert, component, target ) {
component.set({ a: 3 });
assert.equal( component.get( 'c' ), 5 );
assert.equal( component.get( 'cSquared' ), 25 );

@ -1,7 +1,5 @@
import * as assert from 'assert';
export default {
test ( component, target, window ) {
test ( assert, component, target, window ) {
const [ control, test ] = target.querySelectorAll( 'p' );
assert.equal( window.getComputedStyle( control ).color, '' );

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: '<button>+1</button>\n\n<p>0</p>',
test ( component, target, window ) {
test ( assert, component, target, window ) {
const button = target.querySelector( 'button' );
const event = new window.MouseEvent( 'click' );

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
html: '<h1>Hello world!</h1>'
};

@ -1,7 +1,5 @@
import * as assert from 'assert';
export default {
test ( component, target ) {
test ( assert, component, target ) {
const items = component.get( 'items' );
items.forEach( item => item.completed = false );

@ -1,11 +1,9 @@
import * as assert from 'assert';
export default {
data: {
animals: [ 'alpaca', 'baboon', 'capybara' ]
},
html: '<p>alpaca</p><p>baboon</p><p>capybara</p><!--#each animals-->',
test ( component, target ) {
test ( assert, component, target ) {
component.set({ animals: [ 'alpaca', 'baboon', 'caribou', 'dogfish' ] });
assert.equal( target.innerHTML, '<p>alpaca</p><p>baboon</p><p>caribou</p><p>dogfish</p><!--#each animals-->' );
component.set({ animals: [] });

@ -29,7 +29,7 @@ export default {
]
},
html: `<p>animals: aardvark</p><p>animals: buffalo</p><p>animals: chinchilla</p><!--#each category.things--><p>countries: albania</p><p>countries: brazil</p><p>countries: china</p><!--#each category.things--><p>people: alice</p><p>people: bob</p><p>people: carol</p><p>people: dave</p><!--#each category.things--><!--#each categories-->`,
test ( component, target ) {
test ( assert, component, target ) {
// TODO
}
};

@ -4,7 +4,7 @@ export default {
rows: [ 1, 2, 3 ]
},
html: `<div>a, 1</div><div>a, 2</div><div>a, 3</div><!--#each rows--><div>b, 1</div><div>b, 2</div><div>b, 3</div><!--#each rows--><div>c, 1</div><div>c, 2</div><div>c, 3</div><!--#each rows--><!--#each columns-->`,
test ( component, target ) {
test ( assert, component, target ) {
// TODO
}
};

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: '<button>0, 0</button>',
test ( component, target, window ) {
test ( assert, component, target, window ) {
const event = new window.MouseEvent( 'click', {
clientX: 42,
clientY: 42

@ -1,10 +1,8 @@
import * as assert from 'assert';
// TODO gah, JSDOM appears to behave differently to real browsers here... probably need to raise an issue
export default {
html: '<input><!--#if visible-->',
test ( component ) {
test ( assert, component ) {
component.refs.input.focus();
// this should NOT trigger blur event

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: '<button>toggle</button>\n\n<!--#if visible-->',
test ( component, target, window ) {
test ( assert, component, target, window ) {
const button = target.querySelector( 'button' );
const event = new window.MouseEvent( 'click' );

@ -1,7 +1,5 @@
import * as assert from 'assert';
export default {
test ( component ) {
test ( assert, component ) {
let count = 0;
const expected = { x: 1 };

@ -1,7 +1,5 @@
import * as assert from 'assert';
export default {
test ( component ) {
test ( assert, component ) {
let count = 0;
component.on( 'teardown', function () {

@ -1,12 +1,10 @@
import * as assert from 'assert';
export default {
data: {
name: 'world'
},
html: '<h1>Hello world!</h1>',
test ( component, target ) {
test ( assert, component, target ) {
component.set({ name: 'everybody' });
assert.equal( target.innerHTML, '<h1>Hello everybody!</h1>' );
component.teardown();

@ -1,12 +1,10 @@
import * as assert from 'assert';
export default {
data: {
foo: true,
bar: false
},
html: '<p>foo</p><!--#if foo-->\n\n<p>not bar</p><!--#if bar-->',
test ( component, target ) {
test ( assert, component, target ) {
component.set({ foo: false });
assert.equal( target.innerHTML, '<p>not foo</p><!--#if foo-->\n\n<p>not bar</p><!--#if bar-->' );
component.set({ bar: true });

@ -1,11 +1,9 @@
import * as assert from 'assert';
export default {
data: {
visible: true
},
html: '<p>i am visible</p><!--#if visible-->',
test ( component, target ) {
test ( assert, component, target ) {
component.set({ visible: false });
assert.equal( target.innerHTML, '<!--#if visible-->' );
component.set({ visible: true });

@ -1,12 +1,10 @@
import * as assert from 'assert';
export default {
data: {
a: 1,
b: 2
},
html: '<p>1 + 2 = 3</p>',
test ( component, target ) {
test ( assert, component, target ) {
component.set({ a: 3, b: 4 });
assert.equal( target.innerHTML, '<p>3 + 4 = 7</p>' );
}

@ -1,7 +1,5 @@
import * as assert from 'assert';
export default {
test ( component ) {
test ( assert, component ) {
assert.deepEqual( component.events, [ 'render' ]);
component.teardown();
assert.deepEqual( component.events, [ 'render', 'teardown' ]);

@ -1,8 +1,6 @@
import * as assert from 'assert';
export default {
html: '<canvas></canvas>',
test ( component, target ) {
test ( assert, component, target ) {
const canvas = target.querySelector( 'canvas' );
assert.equal( canvas, component.refs.foo );
}

@ -1,5 +1,3 @@
import * as assert from 'assert';
export default {
data: {
x: 0,
@ -8,7 +6,7 @@ export default {
height: 100
},
html: `<svg><rect x="0" y="0" width="100" height="100"></rect></svg>`,
test ( component, target ) {
test ( assert, component, target ) {
const svg = target.querySelector( 'svg' );
const rect = target.querySelector( 'rect' );

@ -1,6 +1,6 @@
import { compile } from '../compiler/index.js';
import parse from '../compiler/parse/index.js';
import * as assert from 'assert';
import assert from 'assert';
import * as path from 'path';
import * as fs from 'fs';
import jsdom from 'jsdom';
@ -141,7 +141,7 @@ describe( 'svelte', () => {
}
if ( config.test ) {
config.test( component, target, window );
config.test( assert, component, target, window );
} else {
component.teardown();
assert.equal( target.innerHTML, '' );

Loading…
Cancel
Save