Skip to content

Like .use functions as a prepend is there any way to add a .postpend? #2155

Answered by kettanaito
rcuching asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @rcuching. That's a good question.

.use() always prepends request handlers because the order of handlers matters. There is no way to "push" handlers (add to the end) and I don't believe there's ever a reason to do so.

Should i just set an individual server.use in every nested describe instead?

You have a few options here.

Option 1: server.use() in individual describe() blocks

describe('1', () => {
  describe('1.1', () => {
    beforeAll(() => server.use(...overrides))
    afterAll(() => server.resetHandlers())
  })

  describe('1.2', () => {
    beforeAll(() => server.use(...overrides))
    afterAll(() => server.resetHandlers())
  })
})

Don't forget to reset the overrides you add with

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rcuching
Comment options

Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants