-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IMiddy and ICorsOptions type definitions (#200)
* Fix IMiddy and ICorsOptions type definitions - integrate typings-tester into npm:test - write typings-tester tests for middy and cors options - minor typescript version bump - modernize typescript setup - provide @types/jest to allow tests to compile * tsc/target = es2015 * Version bump
- Loading branch information
Showing
7 changed files
with
124 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import middy from '../../'; | ||
|
||
describe('🛵 Middy types test suite', () => { | ||
test('"before" should take a function', () => { | ||
const beforeMiddleware = jest.fn(); | ||
|
||
const handler = middy(jest.fn()); | ||
|
||
handler.before(beforeMiddleware); | ||
}) | ||
|
||
test('"after" should take a function', () => { | ||
const afterMiddleware = jest.fn(); | ||
|
||
const handler = middy(jest.fn()); | ||
|
||
handler.after(afterMiddleware); | ||
}) | ||
|
||
test('"onError" should take a function', () => { | ||
const errorMiddleware = jest.fn(); | ||
|
||
const handler = middy(jest.fn()); | ||
|
||
handler.onError(errorMiddleware); | ||
}) | ||
|
||
test('middleware calls can be chained', () => { | ||
const before = jest.fn() | ||
const after = jest.fn() | ||
const onError = jest.fn(); | ||
|
||
const middleware = () => ({ | ||
after, | ||
before, | ||
onError, | ||
}); | ||
|
||
const handler = middy(jest.fn()); | ||
|
||
handler | ||
.use(middleware) | ||
.after(after) | ||
.before(before) | ||
.onError(onError); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import middy from '../../../'; | ||
import { cors } from '../../../middlewares'; | ||
|
||
describe('📦 Middleware Types', () => { | ||
describe('CORS', () => { | ||
it('has an optional argument', () => { | ||
const handler = middy(jest.fn()); | ||
handler.use(cors()); | ||
}) | ||
|
||
it ('has an optional origin field', () => { | ||
const handler = middy(jest.fn()); | ||
handler.use(cors({ | ||
headers: "test-case", | ||
credentials: true, | ||
})); | ||
}) | ||
|
||
it('has an optional headers field', () => { | ||
const handler = middy(jest.fn()); | ||
handler.use(cors({ | ||
origin: 'example.com', | ||
credentials: true, | ||
})); | ||
}) | ||
|
||
it('has an optional credentials field', () => { | ||
const handler = middy(jest.fn()); | ||
handler.use(cors({ | ||
origin: 'example.com', | ||
headers: "test-case", | ||
})); | ||
}) | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters