// testing getStateCode const getStateCode = require('./index') it('extracts from valid string', () => { const s = '{"user": {"address": {"state": "in"}}}' const state = getStateCode(s).getOrElse('an error') console.assert(state === 'IN', state) }) it('handles invalid JSON string', () => { // notice missing quotes const s = '{"user": {"address": {state: in}}}' const state = getStateCode(s).getOrElse('an error') console.assert(state === 'an error', state) }) it('handles missing property', () => { // notice missing address const s = '{"user": {}}' const state = getStateCode(s).getOrElse('an error') console.assert(state === 'an error', state) })