Skip to content

Commit

Permalink
test get as dev dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
abumq committed Jul 23, 2023
1 parent 1e0782c commit ecea07f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
],
"devDependencies": {
"babel-minify": "^0.5.1",
"lodash.get": "^4.4.2",
"mocha": "^10.2.0",
"rimraf": "^3.0.2"
},
Expand Down
15 changes: 9 additions & 6 deletions tests/get.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
const assert = require('assert');
const airsync = require('../src');
const lodashGet = require('lodash.get');
const { fn } = require('../src');

const { queryPerson, getResponse } = require('./utils');
const { getResponse } = require('./utils');

const get = (objOrPromise, path, defaultVal, options = {}) => fn(o => lodashGet(o, path) || defaultVal, options)(objOrPromise)

describe('Test get', () => {
it('Get resolves to correct value', async () => {
const r = await airsync.get(getResponse(), 'status')
const r = await get(getResponse(), 'status')
assert.equal(r, 200)
});

it('Exception handled correctly', async () => {
try {
const r = await airsync.get(getResponse(true), 'status');
const r = await get(getResponse(true), 'status');
assert.fail()
} catch (e) {
assert.equal(e.message, 'Thrown intentionally')
}
});

it('Default values are resolved correctly', async () => {
const r = await airsync.get(getResponse(), 'non-existant', 500)
const r = await get(getResponse(), 'non-existant', 500)
assert.equal(r, 500)
});

it('get options work correctly', async () => {
const timerResult = { start: false, end: false };

const r = await airsync.get(getResponse(), 'status', undefined, {
const r = await get(getResponse(), 'status', undefined, {
startTime: () => timerResult.start = true,
endTime: () => timerResult.end = true,
})
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,11 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

lodash.get@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99"
integrity sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==

lodash@^4.17.11:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
Expand Down

0 comments on commit ecea07f

Please sign in to comment.