Skip to content

Commit

Permalink
added a test for promised data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Huwiler committed Feb 8, 2018
1 parent cce94dd commit d781a16
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/promise-data.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict'

/**
* adonis-bumblebee
*
* (c) Ralph Huwiler <ralph@huwiler.rocks>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const test = require('japa')
const { ioc } = require('@adonisjs/fold')

const setup = require('./setup')

test.group('Promise Data', (group) => {
group.before(async () => {
await setup()
})

test('data can be a promis and will resolve before transforming', async (assert) => {
const Context = ioc.use('Adonis/Src/HttpContext')
const {transform} = new Context()

let data = new Promise((resolve, reject) => {
setTimeout(resolve, 1, {item_id: 3})
})

let transformed = await transform
.item(data, model => ({id: model.item_id}))

assert.equal(transformed.id, 3)
})
})

0 comments on commit d781a16

Please sign in to comment.