Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use isPrototypeOf from Object.prototype #193

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,14 +489,14 @@ app.override = function (s, fn, opts) {

app.use(function first (s1, opts, cb) {
assert(s1 !== server)
assert(server.isPrototypeOf(s1))
assert(Object.prototype.isPrototypeOf.call(server, s1))
assert(s1.count === 1)
s1.use(second)
cb()

function second (s2, opts, cb) {
assert(s2 !== s1)
assert(s1.isPrototypeOf(s2))
assert(Object.prototype.isPrototypeOf.isPrototypeOf.call(s1, s2))
assert(s2.count === 2)
cb()
}
Expand Down
2 changes: 1 addition & 1 deletion test/async-await.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ test('skip override with promise', (t) => {
async function first () {
async function fn (s, opts) {
t.equal(s, server)
t.notOk(server.isPrototypeOf(s))
t.notOk(Object.prototype.isPrototypeOf.call(server, s))
}

fn[Symbol.for('skip-override')] = true
Expand Down
36 changes: 18 additions & 18 deletions test/override.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('custom inheritance', (t) => {

app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
})
})
Expand All @@ -42,15 +42,15 @@ test('custom inheritance multiple levels', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)

cb()

function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
Expand All @@ -72,7 +72,7 @@ test('custom inheritance multiple levels twice', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)
s1.use(third)
Expand All @@ -83,15 +83,15 @@ test('custom inheritance multiple levels twice', (t) => {
function second (s2, opts, cb) {
prev = s2
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}

function third (s3, opts, cb) {
t.not(s3, s1)
t.ok(s1.isPrototypeOf(s3))
t.notOk(prev.isPrototypeOf(s3))
t.ok(Object.prototype.isPrototypeOf.call(s1, s3))
t.notOk(Object.prototype.isPrototypeOf.call(prev, s3))
t.equal(s3.count, 2)
cb()
}
Expand All @@ -113,31 +113,31 @@ test('custom inheritance multiple levels with multiple heads', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(second)

cb()

function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
})

app.use(function third (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.use(fourth)

cb()

function fourth (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
Expand Down Expand Up @@ -176,7 +176,7 @@ test('fastify test case', (t) => {

instance.use((i, opts, cb) => {
t.not(i, instance)
t.ok(instance.isPrototypeOf(i))
t.ok(Object.prototype.isPrototypeOf.call(instance, i))

i.add('test', noop, (err) => {
t.error(err)
Expand Down Expand Up @@ -228,7 +228,7 @@ test('skip override - fastify test case', (t) => {

function first (s, opts, cb) {
t.equal(s, server)
t.notOk(server.isPrototypeOf(s))
t.notOk(Object.prototype.isPrototypeOf.call(server, s))
cb()
}
})
Expand All @@ -252,7 +252,7 @@ test('override can receive options object', (t) => {

app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
}, options)
})
Expand All @@ -279,15 +279,15 @@ test('override can receive options function', (t) => {

app.use(function first (s, opts, cb) {
t.not(s, server)
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
s.foo = 'bar'
cb()
}, options)

app.use(function second (s, opts, cb) {
t.notOk(s.foo)
t.same(opts, { hello: 'world' })
t.ok(server.isPrototypeOf(s))
t.ok(Object.prototype.isPrototypeOf.call(server, s))
cb()
}, p => ({ hello: p.bar }))
})
Expand Down Expand Up @@ -356,7 +356,7 @@ test('custom inheritance override in after', (t) => {

app.use(function first (s1, opts, cb) {
t.not(s1, server)
t.ok(server.isPrototypeOf(s1))
t.ok(Object.prototype.isPrototypeOf.call(server, s1))
t.equal(s1.count, 1)
s1.after(() => {
s1.use(second)
Expand All @@ -366,7 +366,7 @@ test('custom inheritance override in after', (t) => {

function second (s2, opts, cb) {
t.not(s2, s1)
t.ok(s1.isPrototypeOf(s2))
t.ok(Object.prototype.isPrototypeOf.call(s1, s2))
t.equal(s2.count, 2)
cb()
}
Expand Down