uvu#test JavaScript Examples

The following examples show how to use uvu#test. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.spec.js    From kit with MIT License 7 votes vote down vote up
test('serialize_error', () => {
	class FancyError extends Error {
		name = 'FancyError';
		fancy = true;

		/**
		 * @param {string} message
		 * @param {{
		 *   cause?: Error
		 * }} [options]
		 */
		constructor(message, options) {
			// @ts-expect-error go home typescript ur drunk
			super(message, options);
		}
	}

	const error = new FancyError('something went wrong', {
		cause: new Error('sorry')
	});

	const serialized = serialize_error(error, (error) => error.stack);

	assert.equal(
		serialized,
		JSON.stringify({
			name: 'FancyError',
			message: 'something went wrong',
			stack: error.stack,
			cause: {
				name: 'Error',
				message: 'sorry',
				// @ts-expect-error
				stack: error.cause.stack
			},
			fancy: true
		})
	);
});
Example #2
Source File: index.js    From nestie with MIT License 6 votes vote down vote up
test('wrong inputs', () => {
	run(1, undefined);
	run('', undefined);
	run(0, undefined);

	run(null, undefined);
	run(undefined, undefined);
	run(NaN, undefined);
});
Example #3
Source File: debug.js    From rosetta with MIT License 6 votes vote down vote up
test('(debug) exports', () => {
	assert.type(rosetta, 'function', 'exports a function');

	let out = rosetta();
	assert.type(out, 'object', 'returns an object');
	assert.type(out.t, 'function', '~> has "t" function');
	assert.type(out.set, 'function', '~> has "set" function');
	assert.type(out.locale, 'function', '~> has "locale" function');
});
Example #4
Source File: index.js    From uid with MIT License 6 votes vote down vote up
test('length :: 4', () => {
	let i=0, tmp;
	for (; i < 1e3; i++) {
		tmp = uid(4);
		assert.is(tmp.length, 4, `"${tmp}" is not 4 characters!`);
	}

	assert.ok('~> produced 1000 IDs w/ 4 chars each');
});
Example #5
Source File: Count.js    From uvu with MIT License 6 votes vote down vote up
test('should increment count after `button#incr` click', async () => {
	const { container } = ENV.render(Count);

	assert.snapshot(
		container.innerHTML,
		`<button id="decr">--</button><span>5</span><button id="incr">++</button>`
	);

	await ENV.fire(
		container.querySelector('#incr'),
		'click'
	);

	assert.snapshot(
		container.innerHTML,
		`<button id="decr">--</button><span>6</span><button id="incr">++</button>`
	);
});
Example #6
Source File: mount.test.js    From mount-vue-component with MIT License 6 votes vote down vote up
test('it can create create a component instance with unmount hooks', () => {
  let called = false
  const unmounted = () => called = true
  const comp = createComponent({ unmounted })
  const { destroy } = createComponentInstance(comp)
  assert.not(called)
  destroy()
  assert.ok(called)
})
Example #7
Source File: headers.spec.js    From kit with MIT License 6 votes vote down vote up
test('empty headers', () => {
	const headers = new Headers();

	const result = split_headers(headers);

	assert.equal(result, {
		headers: {},
		multiValueHeaders: {}
	});
});
Example #8
Source File: index.js    From nestie with MIT License 5 votes vote down vote up
test('exports', () => {
	assert.type(nestie, 'function');
});
Example #9
Source File: debug.js    From rosetta with MIT License 5 votes vote down vote up
test('(debug) nested', () => {
	let _message = '';
	let _error = console.error;
	console.error = str => {
		_message = str;
	}

	let ctx = rosetta({
		en: {
			fruits: {
				apple: 'apple',
				orange: 'orange',
				grape: 'grape',
			}
		},
		es: {
			fruits: {
				apple: 'manzana',
				orange: 'naranja',
				grape: 'uva',
			}
		}
	});

	ctx.locale('en');
	assert.is(ctx.t('fruits.apple'), 'apple', '(en) fruits.apple');
	assert.is(ctx.t('fruits.orange'), 'orange', '(en) fruits.orange');
	assert.is(ctx.t(['fruits', 'grape']), 'grape', '(en) ["fruits","grape"]');

	assert.is(ctx.t('fruits.404'), undefined, '(en) fruits.404 ~> undefined');
	assert.is(_message, `[rosetta] Missing the "fruits.404" key within the "en" dictionary`, '~> prints error message');

	assert.is(ctx.t('error.404'), undefined, '(en) error.404 ~> undefined');
	assert.is(_message, `[rosetta] Missing the "error.404" key within the "en" dictionary`, '~> prints error message');

	assert.is(ctx.t(['fruits', 'mango']), undefined, '(en) error.404 ~> undefined');
	assert.is(_message, `[rosetta] Missing the "fruits.mango" key within the "en" dictionary`, '~> prints error message');

	// ---

	ctx.locale('es');
	assert.is(ctx.t('fruits.apple'), 'manzana', '(es) fruits.apple');
	assert.is(ctx.t('fruits.orange'), 'naranja', '(es) fruits.orange');
	assert.is(ctx.t(['fruits', 'grape']), 'uva', '(es) ["fruits","grape"]');

	assert.is(ctx.t('fruits.404'), undefined, '(es) fruits.404 ~> undefined');
	assert.is(_message, `[rosetta] Missing the "fruits.404" key within the "es" dictionary`, '~> prints error message');

	assert.is(ctx.t('error.404'), undefined, '(es) error.404 ~> undefined');
	assert.is(_message, `[rosetta] Missing the "error.404" key within the "es" dictionary`, '~> prints error message');

	assert.is(ctx.t(['fruits', 'mango']), undefined, '(es) error.404 ~> undefined');
	assert.is(_message, `[rosetta] Missing the "fruits.mango" key within the "es" dictionary`, '~> prints error message');

	// restore
	console.error = _error;
});
Example #10
Source File: index.js    From uid with MIT License 5 votes vote down vote up
test('exports', () => {
	assert.type(uid, 'function', 'exports function');
});