zxcvbn.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import assert from 'assert';
  2. import { Zxcvbn } from 'misago/services/zxcvbn';
  3. let zxcvbn = null;
  4. describe("Zxcvbn", function() {
  5. afterEach(function() {
  6. delete window.zxcvbn;
  7. });
  8. it("loads library", function(done) {
  9. zxcvbn = new Zxcvbn();
  10. zxcvbn.init({
  11. include: function(lib) {
  12. assert.equal(lib, "misago/js/zxcvbn.js", "library is requested");
  13. }
  14. });
  15. zxcvbn.load().then(function() {
  16. assert.ok(true, "zxcvbn lib was loaded");
  17. done();
  18. });
  19. window.setTimeout(function() {
  20. window.zxcvbn = true;
  21. }, 200);
  22. });
  23. it("scores passwords", function(done) {
  24. zxcvbn = new Zxcvbn();
  25. zxcvbn.init({
  26. include: function(lib) {
  27. assert.equal(lib, 'misago/js/zxcvbn.js', "library is requested");
  28. }
  29. });
  30. zxcvbn.load().then(function() {
  31. assert.equal(zxcvbn.scorePassword('abcd'), 4, "returns pass score");
  32. done();
  33. });
  34. window.setTimeout(function() {
  35. window.zxcvbn = function(password) {
  36. assert.equal(password, 'abcd', "calls underlying zxcvbn lib");
  37. return {score: password.length};
  38. };
  39. }, 200);
  40. });
  41. });