Skip to content

Commit

Permalink
chore(tests): replace equal by strictEqual (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
bertho-zero authored Apr 11, 2021
1 parent c2e55e8 commit 82be08e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion packages/hooks/test/benchmark.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strict as assert } from 'assert';
import * as assert from 'assert';
import { hooks, HookContext, NextFunction, middleware } from '../src/';

const CYCLES = 100000;
Expand Down
16 changes: 8 additions & 8 deletions packages/hooks/test/class.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strict as assert } from 'assert';
import * as assert from 'assert';
import { hooks, middleware, HookContext, NextFunction } from '../src';

interface Dummy {
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('class objectHooks', () => {
hooks(DummyClass, {
sayHi: middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Dave');
assert.strictEqual(ctx.name, 'Dave');

ctx.name = 'Changed';

Expand All @@ -106,8 +106,8 @@ describe('class objectHooks', () => {
hooks(OtherDummy, {
sayHi: middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Changed');
assert.equal(ctx.gna, 42);
assert.strictEqual(ctx.name, 'Changed');
assert.strictEqual(ctx.gna, 42);

await next();
}
Expand All @@ -119,15 +119,15 @@ describe('class objectHooks', () => {
hooks(instance, {
sayHi: middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Changed');
assert.equal(ctx.gna, 42);
assert.equal(ctx.app, 'ok');
assert.strictEqual(ctx.name, 'Changed');
assert.strictEqual(ctx.gna, 42);
assert.strictEqual(ctx.app, 'ok');

await next();
}
]).props({ app: 'ok' })
});

assert.equal(await instance.sayHi('Dave'), 'Hi Changed');
assert.strictEqual(await instance.sayHi('Dave'), 'Hi Changed');
});
});
22 changes: 11 additions & 11 deletions packages/hooks/test/compose.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Adapted from koa-compose (https://github.com/koajs/compose)
import { strict as assert } from 'assert';
import * as assert from 'assert';
import { compose, NextFunction } from '../src';

function wait (ms: number) {
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('Koa Compose', function () {
compose(stack)({});

for (const next of arr) {
assert(isPromise(next), 'one of the functions next is not a Promise');
assert.ok(isPromise(next), 'one of the functions next is not a Promise');
}
});

Expand All @@ -128,7 +128,7 @@ describe('Koa Compose', function () {
});

await compose(stack)({});
assert(called);
assert.ok(called);
});

it('should reject on errors in middleware', () => {
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('Koa Compose', function () {
return compose([])({}, async () => {
called = true;
}).then(function () {
assert(called);
assert.ok(called);
});
});

Expand Down Expand Up @@ -258,7 +258,7 @@ describe('Koa Compose', function () {
])({}).then(() => {
throw new Error('boom');
}, (err) => {
assert(/multiple times/.test(err.message));
assert.ok(/multiple times/.test(err.message));
});
});

Expand All @@ -280,7 +280,7 @@ describe('Koa Compose', function () {
return next();
}
])({}).then(function () {
assert.equal(val, 3);
assert.strictEqual(val, 3);
});
});

Expand All @@ -289,20 +289,20 @@ describe('Koa Compose', function () {

stack.push(async (_context: any, next: NextFunction) => {
const val = await next();
assert.equal(val, 2);
assert.strictEqual(val, 2);
return 1;
});

stack.push(async (_context: any, next: NextFunction) => {
const val = await next();
assert.equal(val, 0);
assert.strictEqual(val, 0);
return 2;
});

const next = async () => 0;

return compose(stack)({}, next).then(function (val) {
assert.equal(val, 1);
assert.strictEqual(val, 1);
});
});

Expand All @@ -314,13 +314,13 @@ describe('Koa Compose', function () {
middleware.push(fn1);

for (const fn of middleware) {
assert.equal(fn, fn1);
assert.strictEqual(fn, fn1);
}

compose(middleware);

for (const fn of middleware) {
assert.equal(fn, fn1);
assert.strictEqual(fn, fn1);
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/test/decorator.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strict as assert } from 'assert';
import * as assert from 'assert';
import { hooks, HookContext, NextFunction, middleware } from '../src';

describe('hookDecorator', () => {
Expand Down Expand Up @@ -26,7 +26,7 @@ describe('hookDecorator', () => {
class DummyClass extends TopLevel {
@hooks(middleware([
async (ctx: HookContext, next: NextFunction) => {
assert.equal(ctx.method, 'sayHi');
assert.strictEqual(ctx.method, 'sayHi');
assert.deepEqual(ctx.arguments, [expectedName]);
assert.deepEqual(ctx.name, expectedName);

Expand Down
52 changes: 26 additions & 26 deletions packages/hooks/test/function.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strict as assert } from 'assert';
import * as assert from 'assert';
import {
hooks,
middleware,
Expand All @@ -18,7 +18,7 @@ describe('functionHooks', () => {
const fn = hooks(hello, []);

assert.notDeepEqual(fn, hello);
assert.ok(getManager(fn) !== null);
assert.notStrictEqual(getManager(fn), null);
});

it('throws an error with non function', () => {
Expand Down Expand Up @@ -49,9 +49,9 @@ describe('functionHooks', () => {
}
]));

assert.equal(typeof fn.original, 'function');
assert.strictEqual(typeof fn.original, 'function');

assert.equal(await fn.original('Dave'), 'Hello Dave');
assert.strictEqual(await fn.original('Dave'), 'Hello Dave');
});

it('can override context.result before, skips method call', async () => {
Expand Down Expand Up @@ -213,43 +213,43 @@ describe('functionHooks', () => {

const result = await second('Dave');

assert.equal(result, 'Hello Dave test value');
assert.strictEqual(result, 'Hello Dave test value');
});

it('creates context with params and converts to arguments', async () => {
const fn = hooks(hello, middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Dave');
assert.strictEqual(ctx.name, 'Dave');

ctx.name = 'Changed';

await next();
}
]).params('name'));

assert.equal(await fn('Dave'), 'Hello Changed');
assert.strictEqual(await fn('Dave'), 'Hello Changed');
});

it('assigns props to context', async () => {
const fn = hooks(hello, middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Dave');
assert.equal(ctx.dev, true);
assert.strictEqual(ctx.name, 'Dave');
assert.strictEqual(ctx.dev, true);

ctx.name = 'Changed';

await next();
}
]).params('name').props({ dev: true }));

assert.equal(await fn('Dave'), 'Hello Changed');
assert.strictEqual(await fn('Dave'), 'Hello Changed');
});

it('assigns props to context by options', async () => {
const fn = hooks(hello, middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Dave');
assert.equal(ctx.dev, true);
assert.strictEqual(ctx.name, 'Dave');
assert.strictEqual(ctx.dev, true);

ctx.name = 'Changed';

Expand All @@ -260,15 +260,15 @@ describe('functionHooks', () => {
props: { dev: true }
}));

assert.equal(await fn('Dave'), 'Hello Changed');
assert.strictEqual(await fn('Dave'), 'Hello Changed');
});

it('ctx.arguments is configurable with named params', async () => {
const modifyArgs = async (ctx: HookContext, next: NextFunction) => {
ctx.arguments[0] = 'Changed';
ctx.arguments.push('no');

assert.equal(ctx.name, ctx.arguments[0]);
assert.strictEqual(ctx.name, ctx.arguments[0]);

await next();
};
Expand All @@ -278,7 +278,7 @@ describe('functionHooks', () => {
const customContext = fn.createContext();
const resultContext = await fn('Daffl', {}, customContext);

assert.equal(resultContext, customContext);
assert.strictEqual(resultContext, customContext);
assert.deepEqual(resultContext, fn.createContext({
arguments: ['Changed', {}, 'no'],
name: 'Changed',
Expand All @@ -290,8 +290,8 @@ describe('functionHooks', () => {
const message = 'Custom message';
const fn = hooks(hello, middleware([
async (ctx, next) => {
assert.equal(ctx.name, 'Dave');
assert.equal(ctx.message, message);
assert.strictEqual(ctx.name, 'Dave');
assert.strictEqual(ctx.message, message);

ctx.name = 'Changed';
await next();
Expand All @@ -301,7 +301,7 @@ describe('functionHooks', () => {
const customContext = fn.createContext({ message });
const resultContext: HookContext = await fn('Dave', {}, customContext);

assert.equal(resultContext, customContext);
assert.strictEqual(resultContext, customContext);
assert.deepEqual(resultContext, fn.createContext({
arguments: ['Changed', {}],
message: 'Custom message',
Expand Down Expand Up @@ -329,8 +329,8 @@ describe('functionHooks', () => {

const result = await exclamation('Bertho');

assert.equal(result, 'Hi Bertho!');
assert.equal(called, 1);
assert.strictEqual(result, 'Hi Bertho!');
assert.strictEqual(called, 1);
});

it('conserves method properties', async () => {
Expand All @@ -347,8 +347,8 @@ describe('functionHooks', () => {

const result = await sayHi('Bertho');

assert.equal(result, 'Hi Bertho!');
assert.equal((sayHi as any)[TEST], (hello as any)[TEST]);
assert.strictEqual(result, 'Hi Bertho!');
assert.strictEqual((sayHi as any)[TEST], (hello as any)[TEST]);
});

it('works with array as middleware', async () => {
Expand All @@ -365,8 +365,8 @@ describe('functionHooks', () => {

const result = await sayHi('Bertho');

assert.equal(result, 'Hi Bertho!');
assert.equal((sayHi as any)[TEST], (hello as any)[TEST]);
assert.strictEqual(result, 'Hi Bertho!');
assert.strictEqual((sayHi as any)[TEST], (hello as any)[TEST]);
});

it('context has own properties', async () => {
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('functionHooks', () => {
})
);

assert.equal(await fn('Dave'), 'Hello Dave');
assert.equal(await fn(), 'Hello Bertho');
assert.strictEqual(await fn('Dave'), 'Hello Dave');
assert.strictEqual(await fn(), 'Hello Bertho');
});
});
6 changes: 3 additions & 3 deletions packages/hooks/test/object.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { strict as assert } from 'assert';
import * as assert from 'assert';
import { hooks, middleware, HookContext, NextFunction } from '../src';

interface HookableObject {
Expand Down Expand Up @@ -27,7 +27,7 @@ describe('objectHooks', () => {
it('hooks object with hook methods, sets method name', async () => {
const hookedObj = hooks(obj, {
sayHi: middleware([async (ctx: HookContext, next: NextFunction) => {
assert.equal(ctx.method, 'sayHi');
assert.strictEqual(ctx.method, 'sayHi');
assert.deepEqual(ctx, new (obj.sayHi as any).Context({
arguments: [ 'David' ],
method: 'sayHi',
Expand Down Expand Up @@ -129,6 +129,6 @@ describe('objectHooks', () => {
}])
});

assert.equal(await obj.sayHi('Dave'), 'Hi Dave?!');
assert.strictEqual(await obj.sayHi('Dave'), 'Hi Dave?!');
});
});

0 comments on commit 82be08e

Please sign in to comment.