You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.6 KiB

  1. /* globals require */
  2. /*!
  3. * Module dependencies.
  4. */
  5. var cordova = require('./helper/cordova'),
  6. BarcodeScanner = require('../www/barcodescanner'),
  7. execSpy,
  8. execWin,
  9. options;
  10. /*!
  11. * Specification.
  12. */
  13. describe('phonegap-plugin-barcodescanner', function () {
  14. beforeEach(function () {
  15. execWin = jasmine.createSpy();
  16. execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
  17. });
  18. describe('BarcodeScanner', function () {
  19. it("BarcodeScanner plugin should exist", function() {
  20. expect(BarcodeScanner).toBeDefined();
  21. expect(typeof BarcodeScanner == 'object').toBe(true);
  22. });
  23. it("should contain a scan function", function() {
  24. expect(BarcodeScanner.scan).toBeDefined();
  25. expect(typeof BarcodeScanner.scan == 'function').toBe(true);
  26. });
  27. it("should contain an encode function", function() {
  28. expect(BarcodeScanner.encode).toBeDefined();
  29. expect(typeof BarcodeScanner.encode == 'function').toBe(true);
  30. });
  31. it("should contain three DestinationType constants", function() {
  32. expect(BarcodeScanner.Encode.TEXT_TYPE).toBe("TEXT_TYPE");
  33. expect(BarcodeScanner.Encode.EMAIL_TYPE).toBe("EMAIL_TYPE");
  34. expect(BarcodeScanner.Encode.PHONE_TYPE).toBe("PHONE_TYPE");
  35. expect(BarcodeScanner.Encode.SMS_TYPE).toBe("SMS_TYPE");
  36. });
  37. });
  38. describe('BarcodeScanner instance', function () {
  39. describe('cordova.exec', function () {
  40. it('should call cordova.exec on next process tick', function (done) {
  41. BarcodeScanner.scan(function() {}, function() {}, {});
  42. setTimeout(function () {
  43. expect(execSpy).toHaveBeenCalledWith(
  44. jasmine.any(Function),
  45. jasmine.any(Function),
  46. 'BarcodeScanner',
  47. 'scan',
  48. jasmine.any(Object)
  49. );
  50. done();
  51. }, 100);
  52. });
  53. it('should call cordova.exec on next process tick', function (done) {
  54. BarcodeScanner.encode("", "",function() {}, function() {}, {});
  55. setTimeout(function () {
  56. expect(execSpy).toHaveBeenCalledWith(
  57. jasmine.any(Function),
  58. jasmine.any(Function),
  59. 'BarcodeScanner',
  60. 'encode',
  61. jasmine.any(Object)
  62. );
  63. done();
  64. }, 100);
  65. });
  66. });
  67. });
  68. });