Skip to content

Commit

Permalink
feat(api): accept a params object, a swal function, or nothing (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenflow authored Mar 2, 2018
1 parent 3bf0e07 commit b37fb3f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The following options can be React elements:
const swal = require('sweetalert2')
const withReactContent = require('sweetalert2-react-content')

const mySwal = withReactContent({ swal })
const mySwal = withReactContent(swal)
// or just `const mySwal = withReactContent()`

mySwal({
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# TODO

- put build test (test-build.html) in automated harness
- enable greenkeeper

(also search "TODO" in code)
7 changes: 6 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const { mounts } = require('./mounts')

const noop = () => {}

function sweetalert2ReactContent({ swal = require('sweetalert2') } = {}) {
function sweetalert2ReactContent(arg) {
const options =
typeof arg === 'object'
? arg
: { swal: typeof arg === 'function' ? arg : require('sweetalert2') }
const { swal } = options
const fn = (...args) => {
const params = Object.assign({}, toParams(args)) // safe to mutate this

Expand Down
5 changes: 3 additions & 2 deletions tests/units/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ describe('sweetalert2-react-content', () => {
expect(params.title).toEqual('foo')
return { value: 'bar' }
}
Object.assign(mockSwal, swal)
const mySwal = withReactContent({ swal: mockSwal })
Object.assign(mockSwal, swal, { method: () => {} })
const mySwal = withReactContent(mockSwal)
expect(mySwal.method).toEqual(mockSwal.method)
const result = await mySwal({ title: 'foo' })
expect(result).toEqual({ value: 'bar' })
})
Expand Down

0 comments on commit b37fb3f

Please sign in to comment.