parse.asynct.js 782 B

123456789101112131415161718192021222324252627282930313233
  1. var es = require('../')
  2. , it = require('it-is').style('colour')
  3. exports ['es.parse() writes parsing errors with console.error'] = function (test) {
  4. var parseStream = es.parse()
  5. var oldConsoleError = console.error
  6. console.error = function () {
  7. console.error = oldConsoleError
  8. it(arguments.length > 0).ok()
  9. test.done()
  10. }
  11. // bare word is not valid JSON
  12. parseStream.write('A')
  13. }
  14. exports ['es.parse({error: true(thy)}) emits error events from parsing'] = function (test) {
  15. var parseStream = es.parse({error: 1})
  16. var expectedError
  17. try {
  18. JSON.parse('A')
  19. } catch(e) {
  20. expectedError = e
  21. }
  22. parseStream.on('error', function (e) {
  23. it(e).deepEqual(expectedError)
  24. process.nextTick(function () {
  25. test.done()
  26. })
  27. }).write('A')
  28. }