diff --git a/dist/abstract-tester.d.ts b/dist/abstract-tester.d.ts index 6deb2c8..357be70 100644 --- a/dist/abstract-tester.d.ts +++ b/dist/abstract-tester.d.ts @@ -7,9 +7,9 @@ export default abstract class AbstractTester { constructor(); setPriorHtml(html: string): void; current(): string; - next(): Diff; + next(): Promise; abstract fillIn(name: string, value: string): void; abstract click(selector: Object | string): void; - protected abstract nextHtml(): string; + protected abstract nextHtml(): Promise; } export {}; diff --git a/dist/abstract-tester.js b/dist/abstract-tester.js index 5ae1d81..8f2d7db 100644 --- a/dist/abstract-tester.js +++ b/dist/abstract-tester.js @@ -1,4 +1,40 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; Object.defineProperty(exports, "__esModule", { value: true }); var AbstractTester = /** @class */ (function () { function AbstractTester() { @@ -11,10 +47,26 @@ var AbstractTester = /** @class */ (function () { return this.priorHtml; }; AbstractTester.prototype.next = function () { - var diffA = this.priorHtml; - var diffB = this.nextHtml(); - this.priorHtml = this.nextHtml(); - return { diffA: diffA, diffB: diffB }; + return __awaiter(this, void 0, void 0, function () { + var diffA, diffB, _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + diffA = this.priorHtml; + return [4 /*yield*/, this.nextHtml()]; + case 1: + diffB = _b.sent(); + _a = this; + return [4 /*yield*/, this.nextHtml()]; + case 2: + _a.priorHtml = _b.sent(); + return [2 /*return*/, { + diffA: diffA, + diffB: diffB + }]; + } + }); + }); }; return AbstractTester; }()); diff --git a/dist/serializer.js b/dist/serializer.js index 8be29be..dc9a561 100644 --- a/dist/serializer.js +++ b/dist/serializer.js @@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.print = exports.test = void 0; var jest_serializer_vue_1 = __importDefault(require("jest-serializer-vue")); var snapshot_diff_serializer_1 = __importDefault(require("snapshot-diff-serializer")); function test(value) { @@ -10,13 +11,12 @@ function test(value) { } exports.test = test; function print(value, serializer) { - var result = ''; if (jest_serializer_vue_1.default.test(value)) { - result = jest_serializer_vue_1.default.print.apply(null, arguments); + return jest_serializer_vue_1.default.print.apply(null, [value, serializer]); } else if (snapshot_diff_serializer_1.default.test(value)) { - result = snapshot_diff_serializer_1.default.print.apply(null, arguments); + return snapshot_diff_serializer_1.default.print.apply(null, [value, serializer]); } - return result; + return ''; } exports.print = print; diff --git a/dist/vue-tester.d.ts b/dist/vue-tester.d.ts index 4f9c1a9..59d5acf 100644 --- a/dist/vue-tester.d.ts +++ b/dist/vue-tester.d.ts @@ -1,13 +1,16 @@ import AbstractTester from './abstract-tester'; -declare type VueWrapper = { +interface VueWrapper { html(): string; find(selector: object | string): any; -}; + vm: { + $nextTick(): Promise; + }; +} export default class VueTester extends AbstractTester { private wrapper; constructor(wrapper: VueWrapper); fillIn(name: string, value: string): void; click(selector: string | object): void; - protected nextHtml(): string; + protected nextHtml(): Promise; } export {}; diff --git a/dist/vue-tester.js b/dist/vue-tester.js index 7c50d79..6d74fc8 100644 --- a/dist/vue-tester.js +++ b/dist/vue-tester.js @@ -1,14 +1,53 @@ "use strict"; var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -19,7 +58,7 @@ var VueTester = /** @class */ (function (_super) { function VueTester(wrapper) { var _this = _super.call(this) || this; _this.wrapper = wrapper; - _this.setPriorHtml(_this.nextHtml()); + _this.setPriorHtml(wrapper.html()); return _this; } VueTester.prototype.fillIn = function (name, value) { @@ -31,7 +70,16 @@ var VueTester = /** @class */ (function (_super) { this.wrapper.find(selector).trigger('click'); }; VueTester.prototype.nextHtml = function () { - return this.wrapper.html(); + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, this.wrapper.vm.$nextTick()]; + case 1: + _a.sent(); + return [2 /*return*/, this.wrapper.html()]; + } + }); + }); }; return VueTester; }(abstract_tester_1.default));