How to use checker method in mountebank

Best JavaScript code snippet using mountebank

Game.js

Source:Game.js Github

copy

Full Screen

1class Game {2 constructor() {3 this.board = new Board();4 this.players = this.createPlayers();5 }6 /** 7 * Creates two player objects8 * @return {array} players - array of two Player objects9 */10 createPlayers() {11 const players = [new Player('Player 1', 1, 'black', true),12 new Player('Player 2', 2, 'red')];13 return players;14 }15 /** 16 * Returns active player17 * @return {Object} player - The active player18 */19 get activePlayer() {20 return this.players.find(player => player.active);21 }22 23 /**24 * Returns opposing (inactive) player25 * @returns {Object} player - the opposing player26 */27 get opposingPlayer() {28 return this.players.find(player => !player.active);29 }30 /** 31 * Initializes game32 */33 startGame(){34 this.board.drawHTMLBoard();35 document.getElementById('turn-indicator').style.display = 'inline-flex';36 this.updateTurnIndicator();37 //draw player one's checkers38 const playerOneSpaces = [];39 for (let y=this.board.rows - 1; y > this.board.rows - 4; y--) {40 for (let x=0; x < this.board.columns; x++) {41 if ((x % 2 === 1 && y % 2 === 0) ||42 (x % 2 === 0 && y % 2 === 1)) {43 playerOneSpaces.push(this.board.spaces[x][y]);44 }45 }46 }47 this.players[0].drawHTMLCheckers(playerOneSpaces);48 //draw player two's checkers49 const playerTwoSpaces = [];50 for (let y=0; y < 3; y++) {51 for (let x=0; x < this.board.columns; x++) {52 if ((x % 2 === 1 && y % 2 === 0) ||53 (x % 2 === 0 && y % 2 === 1)) {54 playerTwoSpaces.push(this.board.spaces[x][y]);55 }56 }57 }58 this.players[1].drawHTMLCheckers(playerTwoSpaces);59 }60 /**61 * Updates turn indicator to current active player 62 */63 updateTurnIndicator() {64 const turnIndicator = document.getElementById('turn-indicator');65 const checkerDiv = turnIndicator.querySelector('.checker');66 const textIndicator = turnIndicator.querySelector('#text-indicator');67 checkerDiv.style.backgroundColor = this.activePlayer.color;68 textIndicator.textContent = `${this.activePlayer.name}'s turn`;69 textIndicator.style.color = this.activePlayer.color;70 }71 /**72 * Branches code depending on space clicked by player73 * @param {Object} event - click event object74 */75 handleClick(event) {76 //check for active checker and get HTML element clicked by player77 const activeChecker = this.activePlayer.activeChecker;78 const clickedDiv = this.getClickedDiv(event);79 if (!activeChecker) {//no active checker - first click80 //check that player clicked on a checker81 if (clickedDiv.classList.contains('checker')) {82 const checker = this.activePlayer.checkers.find(checker => checker.id === clickedDiv.id);83 if (checker) {//player clicked their own checker - make it active84 checker.active = true;85 clickedDiv.parentElement.classList.toggle('active');86 }87 }88 } else if (clickedDiv.id === activeChecker.id && !activeChecker.alreadyJumpedThisTurn) {//player clicked active checker - make it inactive (unless in middle of multi-jump)89 90 activeChecker.active = false;91 clickedDiv.parentElement.classList.toggle('active');92 } else if (clickedDiv.classList.contains('space') &&93 !clickedDiv.children[0]) {//player clicked empty space - move (if valid move)94 95 this.attemptMove(clickedDiv);96 }97 }98 /**99 * Returns div for item clicked - empty space or checker (including if player clicked space containing checker)100 * @param {Object} event - click event object101 * @returns {Object} clickedDiv - HTML element that player clicked on (or checker in space that player clicked on)102 */103 getClickedDiv(event) {104 let clickedDiv = null;105 if (event.target.classList.contains('space') && event.target.children[0]) {106 clickedDiv = event.target.children[0];107 } else {108 clickedDiv = event.target;109 }110 return clickedDiv;111 }112 /**113 * Checks validity of checker move114 * @param {Object} clickedSpaceDiv - HTML space clicked by player115 */116 attemptMove(clickedSpaceDiv) {117 const col = clickedSpaceDiv.id.charAt(6);118 const row = clickedSpaceDiv.id.charAt(8);119 const clickedSpace = this.board.spaces[col][row];120 const activeChecker = this.activePlayer.activeChecker;121 const activeCheckerSpace = activeChecker.space;122 let opponentChecker = null;123 let checkerWasMoved = false;124 let checkerWasJumped = false;125 126 if (this.activePlayer.id === 1 || this.activePlayer.activeChecker.isKing) {//player one or king checker - move up the board127 if (!activeChecker.alreadyJumpedThisTurn &&128 clickedSpace.y === activeCheckerSpace.y - 1 &&129 (clickedSpace.x === activeCheckerSpace.x - 1 ||130 clickedSpace.x === activeCheckerSpace.x + 1)) {//basic move forward131 132 activeChecker.moveChecker(clickedSpace);133 checkerWasMoved = true;134 } else if (clickedSpace.y === activeCheckerSpace.y - 2 &&135 (136 (clickedSpace.x === activeCheckerSpace.x - 2 && 137 (opponentChecker = this.checkForOpponentChecker(activeCheckerSpace.x - 1, activeCheckerSpace.y - 1, this.activePlayer))138 )139 ||140 (clickedSpace.x === activeCheckerSpace.x + 2 && 141 (opponentChecker = this.checkForOpponentChecker(activeCheckerSpace.x + 1, activeCheckerSpace.y - 1, this.activePlayer))142 )143 )144 ) {//jump opponent's checker145 activeChecker.jumpChecker(clickedSpace, opponentChecker);146 checkerWasMoved = true;147 checkerWasJumped = true;148 }149 }150 if (this.activePlayer.id === 2 || this.activePlayer.activeChecker.isKing) {//player two or king checker - move down the board151 if (!activeChecker.alreadyJumpedThisTurn &&152 clickedSpace.y === activeCheckerSpace.y + 1 &&153 (clickedSpace.x === activeCheckerSpace.x - 1 ||154 clickedSpace.x === activeCheckerSpace.x + 1)) {//basic move forward155 activeChecker.moveChecker(clickedSpace);156 checkerWasMoved = true;157 } else if (clickedSpace.y === activeCheckerSpace.y + 2 &&158 (159 (clickedSpace.x === activeCheckerSpace.x - 2 &&160 (opponentChecker = this.checkForOpponentChecker(activeCheckerSpace.x - 1, activeCheckerSpace.y + 1, this.activePlayer))161 )162 ||163 (clickedSpace.x === activeCheckerSpace.x + 2 && 164 (opponentChecker = this.checkForOpponentChecker(activeCheckerSpace.x + 1, activeCheckerSpace.y + 1, this.activePlayer))165 )166 )167 ) {//jump opponent's checker168 activeChecker.jumpChecker(clickedSpace, opponentChecker);169 checkerWasMoved = true;170 checkerWasJumped = true;171 }172 }173 if (checkerWasMoved) {174 this.updateGameState(checkerWasJumped);175 }176 }177 /**178 * Checks space located at (x,y) for opponent's checker179 * @param {integer} x - x coordinate of space to be checked180 * @param {integer} y - y coordinate of space to be checked181 * @param {Object} player - player who's checking this space for their opponent's checker182 * @returns {Object | null} checker - opponent's checker in indicated space (if there is one)183 */184 checkForOpponentChecker(x, y, player) {185 let checker = null;186 const space = this.board.spaces[x][y];187 if (space.checker && space.checker.owner !== player) {188 checker = space.checker;189 }190 return checker;191 }192 /**193 * Updates game state after checker is moved194 * @param {boolean} checkerWasJumped - represents whether last move was a jump195 */196 updateGameState(checkerWasJumped) {197 if (!this.checkForWin()) {//no win - keep playing198 this.checkForKing(this.activePlayer.activeChecker);199 200 if (!checkerWasJumped || //last move was not jump201 !this.checkForJump(this.activePlayer.activeChecker)) {//active player cannot make another jump with active checker202 this.activePlayer.activeChecker.alreadyJumpedThisTurn = false;203 this.activePlayer.activeChecker.active = false;204 this.switchPlayers();205 } else if (checkerWasJumped && //last move was jump206 this.checkForJump(this.activePlayer.activeChecker)) {//active player can jump again with active checker207 document.getElementById(this.activePlayer.activeChecker.space.id).classList.toggle('active');208 }209 } else {//win achieved210 document.getElementById('game-over').textContent = `${this.activePlayer.name} wins!`;211 document.getElementById('game-over').style.color = this.activePlayer.color;212 }213 }214 /**215 * Checks whether a win condition has been met216 * @returns {boolean} win - expresses whether any win condition has been met217 */218 checkForWin() {219 let win = false;220 if (this.opposingPlayer.remainingCheckers.length === 0) {//opponent has no checkers left221 win = true;222 }223 if (!(this.opposingPlayer.remainingCheckers.find(checker => this.checkForMove(checker)) !== undefined ||224 this.opposingPlayer.remainingCheckers.find(checker => this.checkForJump(checker)) !== undefined)) {//opponent has no moves left225 win = true;226 }227 return win;228 }229 /**230 * Checks whether active checker becomes king after being moved231 * @param {Object} checker - checker to be checked for becoming king232 */233 checkForKing(checker) {234 const checkerSpace = checker.space;235 if ((checker.owner.id === 2 && checkerSpace.y === this.board.rows - 1) ||236 (checker.owner.id === 1 && checkerSpace.y === 0)) {237 checker.makeKing();238 }239 }240 /**241 * Checks whether player can do basic move with a certain checker242 * @param {Object} checker - checker being checked to see if it can move243 * @returns {boolean} canMove - represents whether checker can move244 */245 checkForMove(checker) {246 let canMove = false;247 const checkerSpace = checker.space;248 if (checker.owner.id === 1 || checker.isKing) {//player one or king checker - move up the board249 if ( (this.board.spaces[checkerSpace.x + 1] &&250 this.board.spaces[checkerSpace.x + 1][checkerSpace.y - 1] && //check that space exists on board251 this.board.spaces[checkerSpace.x + 1][checkerSpace.y - 1].checker === null) //check that space is empty252 ||253 (this.board.spaces[checkerSpace.x - 1] &&254 this.board.spaces[checkerSpace.x - 1][checkerSpace.y - 1] && //check that space exists on board255 this.board.spaces[checkerSpace.x - 1][checkerSpace.y - 1].checker === null) //check that space is empty256 ) {257 canMove = true;258 }259 }260 if (checker.owner.id === 2 || checker.isKing) {//player two or king checker - move down the board261 262 if ( (this.board.spaces[checkerSpace.x + 1] &&263 this.board.spaces[checkerSpace.x + 1][checkerSpace.y + 1] && //check that space exists on board264 this.board.spaces[checkerSpace.x + 1][checkerSpace.y + 1].checker === null) //check that space is empty)265 ||266 (this.board.spaces[checkerSpace.x - 1] &&267 this.board.spaces[checkerSpace.x - 1][checkerSpace.y + 1] && //check that space exists on board268 this.board.spaces[checkerSpace.x - 1][checkerSpace.y + 1].checker === null) //check that space is empty269 ) {270 canMove = true;271 }272 }273 return canMove;274 }275 /**276 * Checks whether player can perform a jump with a certain checker277 * @param {Object} checker - checker being checked to see if it can perform jump278 * @returns {boolean} canJump - boolean value representing whether checker can perform jump279 */280 checkForJump(checker) {281 let canJump = false;282 const checkerSpace = checker.space;283 if (checker.owner.id === 1 || checker.isKing) {//player one or king checker - jump up the board284 if ((this.board.spaces[checkerSpace.x + 2] &&285 this.board.spaces[checkerSpace.x + 2][checkerSpace.y - 2] && //check that space exists on board286 this.board.spaces[checkerSpace.x + 2][checkerSpace.y - 2].checker === null && //check that space is empty287 this.checkForOpponentChecker(checkerSpace.x + 1, checkerSpace.y - 1, checker.owner))288 ||289 (this.board.spaces[checkerSpace.x - 2] &&290 this.board.spaces[checkerSpace.x - 2][checkerSpace.y - 2] && //check that space exists on board291 this.board.spaces[checkerSpace.x - 2][checkerSpace.y - 2].checker === null && //check that space is empty292 this.checkForOpponentChecker(checkerSpace.x - 1, checkerSpace.y - 1, checker.owner))) {293 canJump = true;294 }295 }296 if (checker.owner.id === 2 || checker.isKing) {//player two or king checker - jump down the board297 298 if ((this.board.spaces[checkerSpace.x + 2] &&299 this.board.spaces[checkerSpace.x + 2][checkerSpace.y + 2] && //check that space exists on board300 this.board.spaces[checkerSpace.x + 2][checkerSpace.y + 2].checker === null && //check that space is empty301 this.checkForOpponentChecker(checkerSpace.x + 1, checkerSpace.y + 1, checker.owner))302 ||303 (this.board.spaces[checkerSpace.x - 2] &&304 this.board.spaces[checkerSpace.x - 2][checkerSpace.y + 2] && //check that space exists on board305 this.board.spaces[checkerSpace.x - 2][checkerSpace.y + 2].checker === null && //check that space is empty306 this.checkForOpponentChecker(checkerSpace.x - 1, checkerSpace.y + 1, checker.owner))) {307 canJump = true;308 }309 }310 return canJump;311 }312 /** 313 * Switches active player314 */315 switchPlayers() {316 for (let player of this.players) {317 player.active = player.active === true ? false : true;318 }319 this.updateTurnIndicator();320 }...

Full Screen

Full Screen

require-curly-braces.js

Source:require-curly-braces.js Github

copy

Full Screen

1var Checker = require('../../../lib/checker');2var expect = require('chai').expect;3var getPosition = require('../../../lib/errors').getPosition;4describe('rules/require-curly-braces', function() {5 var checker;6 beforeEach(function() {7 checker = new Checker();8 checker.registerDefaultRules();9 });10 it('should report missing `if` braces', function() {11 checker.configure({ requireCurlyBraces: ['if'] });12 expect(checker.checkString('if (x) x++;')).to.have.one.validation.error.from('requireCurlyBraces');13 });14 it('should not report `if` with braces', function() {15 checker.configure({ requireCurlyBraces: ['if'] });16 expect(checker.checkString('if (x) { x++; }')).to.have.no.errors();17 });18 it('should report missing `else` braces', function() {19 checker.configure({ requireCurlyBraces: ['else'] });20 expect(checker.checkString('if (x) x++; else x--;')).to.have.one.validation.error.from('requireCurlyBraces');21 });22 it('should not report `else` with braces', function() {23 checker.configure({ requireCurlyBraces: ['else'] });24 expect(checker.checkString('if (x) x++; else { x--; }')).to.have.no.errors();25 });26 it('should report missing `while` braces', function() {27 checker.configure({ requireCurlyBraces: ['while'] });28 expect(checker.checkString('while (x) x++;')).to.have.one.validation.error.from('requireCurlyBraces');29 });30 it('should not report `while` with braces', function() {31 checker.configure({ requireCurlyBraces: ['while'] });32 expect(checker.checkString('while (x) { x++; }')).to.have.no.errors();33 });34 it('should report missing `for` braces', function() {35 checker.configure({ requireCurlyBraces: ['for'] });36 expect(checker.checkString('for (;;) x++;')).to.have.one.validation.error.from('requireCurlyBraces');37 });38 it('should not report `for` with braces', function() {39 checker.configure({ requireCurlyBraces: ['for'] });40 expect(checker.checkString('for (;;) { x++; }')).to.have.no.errors();41 });42 it('should report missing `for in` braces', function() {43 checker.configure({ requireCurlyBraces: ['for'] });44 expect(checker.checkString('for (i in z) x++;')).to.have.one.validation.error.from('requireCurlyBraces');45 });46 it('should not report `for in` with braces', function() {47 checker.configure({ requireCurlyBraces: ['for'] });48 expect(checker.checkString('for (i in z) { x++; }')).to.have.no.errors();49 });50 it('should report missing `for of` braces', function() {51 checker.configure({ requireCurlyBraces: ['for'] });52 expect(checker.checkString('for (i of z) x++;')).to.have.one.validation.error.from('requireCurlyBraces');53 });54 it('should not report `for of` with braces', function() {55 checker.configure({ requireCurlyBraces: ['for'] });56 expect(checker.checkString('for (i of z) { x++; }')).to.have.no.errors();57 });58 it('should report missing `do` braces', function() {59 checker.configure({ requireCurlyBraces: ['do'] });60 expect(checker.checkString('do x++; while (x);')).to.have.one.validation.error.from('requireCurlyBraces');61 });62 it('should not report `do` with braces', function() {63 checker.configure({ requireCurlyBraces: ['do'] });64 expect(checker.checkString('do { x++; } while (x);')).to.have.no.errors();65 });66 it('should report missing `case` braces', function() {67 checker.configure({ requireCurlyBraces: ['case'] });68 expect(checker.checkString('switch(x){case 1:a=b;}')).to.have.one.validation.error.from('requireCurlyBraces');69 });70 it('should report missing `case` braces, but not missing `default`', function() {71 checker.configure({ requireCurlyBraces: ['case'] });72 expect(checker.checkString('switch(x){case 1:a=b;default:a=c;}'))73 .to.have.one.validation.error.from('requireCurlyBraces');74 });75 it('should not report `case` with braces', function() {76 checker.configure({ requireCurlyBraces: ['case'] });77 expect(checker.checkString('switch(x){case 1:{a=b;}}')).to.have.no.errors();78 });79 it('should not report empty `case` with missing braces', function() {80 checker.configure({ requireCurlyBraces: ['case'] });81 expect(checker.checkString('switch(x){case 0:case 1:{a=b;}}')).to.have.no.errors();82 });83 it('should report missing `default` braces', function() {84 checker.configure({ requireCurlyBraces: ['default'] });85 expect(checker.checkString('switch(x){default:a=b;}')).to.have.one.validation.error.from('requireCurlyBraces');86 });87 it('should report missing `default` braces, but not missing `case`', function() {88 checker.configure({ requireCurlyBraces: ['default'] });89 expect(checker.checkString('switch(x){case 1:a=b;default:a=c;}'))90 .to.have.one.validation.error.from('requireCurlyBraces');91 });92 it('should not report `default` with braces', function() {93 checker.configure({ requireCurlyBraces: ['default'] });94 expect(checker.checkString('switch(x){default:{a=b;}}')).to.have.no.errors();95 });96 it('should report missing braces in `case` with expression', function() {97 checker.configure({ requireCurlyBraces: ['case'] });98 expect(checker.checkString('switch(true){case x&&y:a=b;}'))99 .to.have.one.validation.error.from('requireCurlyBraces');100 });101 it('should report missing braces in `case` with more that one consequent statement', function() {102 checker.configure({ requireCurlyBraces: ['case'] });103 expect(checker.checkString('switch(x){case 1:a=b;c=d;}'))104 .to.have.one.validation.error.from('requireCurlyBraces');105 });106 it('should not report missing braces in `case` with braces', function() {107 checker.configure({ requireCurlyBraces: ['case'] });108 expect(checker.checkString('switch(x){case 1:{a=b;c=d;}}')).to.have.no.errors();109 });110 it('should ignore method name if it\'s a reserved word (#180)', function() {111 checker.configure({ requireCurlyBraces: ['catch'] });112 expect(checker.checkString('promise.catch()')).to.have.no.errors();113 });114 it('should report on all optionally curly braced keywords if a value of true is supplied', function() {115 checker.configure({ requireCurlyBraces: true });116 expect(checker.checkString('if (x) x++;')).to.have.errors();117 expect(checker.checkString('if (x) {x++} else x--;')).to.have.errors();118 expect(checker.checkString('for (x = 0; x < 10; x++) x++;')).to.have.errors();119 expect(checker.checkString('while (x) x++;')).to.have.errors();120 expect(checker.checkString('do x++; while(x < 5);')).to.have.errors();121 expect(checker.checkString('try {x++;} catch(e) throw e;')).to.have.errors();122 expect(checker.checkString('switch(\'4\'){ case \'4\': break; }')).to.have.errors();123 expect(checker.checkString('switch(\'4\'){ case \'4\': {break;} default: 1; }')).to.have.errors();124 expect(checker.checkString('with(x) console.log(toString());')).to.have.errors();125 });126 it('should correctly set pointer (#799)', function() {127 checker.configure({ requireCurlyBraces: ['else'] });128 var error = checker.checkString([129 'function a() {',130 'if (foo === 1)',131 ' return 1;',132 'else ',133 ' return 3;',134 '}'135 ].join('\n')).getErrorList()[ 0 ];136 expect(getPosition(error).column).to.equal(2);137 expect(getPosition(error).line).to.equal(4);138 });139 it('should not report missing `else` braces for `else if`', function() {140 checker.configure({ requireCurlyBraces: ['else'] });141 expect(checker.checkString('if (x) { x++; } else if (x) { x++; }')).to.have.no.errors();142 });143 describe('option with exceptions', function() {144 it('should report on if and else', function() {145 checker.configure({146 requireCurlyBraces: {147 allExcept: ['return', 'break', 'continue'],148 keywords: true149 }150 });151 expect(checker.checkString('if (x) x++;')).to.have.errors();152 expect(checker.checkString('if (x) {x++} else x--;')).to.have.errors();153 expect(checker.checkString('for (x = 0; x < 10; x++) x++;')).to.have.errors();154 expect(checker.checkString('while (x) x++;')).to.have.errors();155 expect(checker.checkString('do x++; while(x < 5);')).to.have.errors();156 expect(checker.checkString('try {x++;} catch(e) throw e;')).to.have.errors();157 expect(checker.checkString('switch(\'4\'){ case \'4\': break; }')).to.have.errors();158 expect(checker.checkString('switch(\'4\'){ case \'4\': {break;} default: 1; }')).to.have.errors();159 expect(checker.checkString('with(x) console.log(toString());')).to.have.errors();160 });161 it('should report on if and else', function() {162 checker.configure({163 requireCurlyBraces: {164 allExcept: ['return', 'break', 'continue'],165 keywords: ['if', 'else']166 }167 });168 expect(checker.checkString('function a() { if (x) x++; }')).to.have.errors();169 expect(checker.checkString('function a() { if (x) {x++} else x--; }')).to.have.errors();170 });171 it('should not report on if and else with exceptions', function() {172 checker.configure({173 requireCurlyBraces: {174 allExcept: ['return', 'break', 'continue'],175 keywords: ['if', 'else']176 }177 });178 expect(checker.checkString('function a() { if (x) return; }')).to.have.no.errors();179 expect(checker.checkString('function a() { if (x) return; else return; }')).to.have.no.errors();180 });181 });...

Full Screen

Full Screen

InlineSpellCheckerContent.jsm

Source:InlineSpellCheckerContent.jsm Github

copy

Full Screen

1/* vim: set ts=2 sw=2 sts=2 tw=80: */2/* This Source Code Form is subject to the terms of the Mozilla Public3 * License, v. 2.0. If a copy of the MPL was not distributed with this4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */5"use strict";6var { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;7var { InlineSpellChecker, SpellCheckHelper } =8 Cu.import("resource://gre/modules/InlineSpellChecker.jsm", {});9this.EXPORTED_SYMBOLS = [ "InlineSpellCheckerContent" ]10var InlineSpellCheckerContent = {11 _spellChecker: null,12 _manager: null,13 initContextMenu(event, editFlags, messageManager) {14 this._manager = messageManager;15 let spellChecker;16 if (!(editFlags & (SpellCheckHelper.TEXTAREA | SpellCheckHelper.INPUT))) {17 // Get the editor off the window.18 let win = event.target.ownerGlobal;19 let editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)20 .getInterface(Ci.nsIWebNavigation)21 .QueryInterface(Ci.nsIInterfaceRequestor)22 .getInterface(Ci.nsIEditingSession);23 spellChecker = this._spellChecker =24 new InlineSpellChecker(editingSession.getEditorForWindow(win));25 } else {26 // Use the element's editor.27 spellChecker = this._spellChecker =28 new InlineSpellChecker(event.target.QueryInterface(Ci.nsIDOMNSEditableElement).editor);29 }30 this._spellChecker.initFromEvent(event.rangeParent, event.rangeOffset)31 this._addMessageListeners();32 if (!spellChecker.canSpellCheck) {33 return { canSpellCheck: false,34 initialSpellCheckPending: true,35 enableRealTimeSpell: false };36 }37 if (!spellChecker.mInlineSpellChecker.enableRealTimeSpell) {38 return { canSpellCheck: true,39 initialSpellCheckPending: spellChecker.initialSpellCheckPending,40 enableRealTimeSpell: false };41 }42 let dictionaryList = {};43 let realSpellChecker = spellChecker.mInlineSpellChecker.spellChecker;44 realSpellChecker.GetDictionaryList(dictionaryList, {});45 // The original list we get is in random order. We need our list to be46 // sorted by display names.47 dictionaryList = spellChecker.sortDictionaryList(dictionaryList.value).map((obj) => {48 return obj.id;49 });50 spellChecker.mDictionaryNames = dictionaryList;51 return { canSpellCheck: spellChecker.canSpellCheck,52 initialSpellCheckPending: spellChecker.initialSpellCheckPending,53 enableRealTimeSpell: spellChecker.enabled,54 overMisspelling: spellChecker.overMisspelling,55 misspelling: spellChecker.mMisspelling,56 spellSuggestions: this._generateSpellSuggestions(),57 currentDictionary: spellChecker.mInlineSpellChecker.spellChecker.GetCurrentDictionary(),58 dictionaryList };59 },60 uninitContextMenu() {61 for (let i of this._messages)62 this._manager.removeMessageListener(i, this);63 this._manager = null;64 this._spellChecker = null;65 },66 _generateSpellSuggestions() {67 let spellChecker = this._spellChecker.mInlineSpellChecker.spellChecker;68 try {69 spellChecker.CheckCurrentWord(this._spellChecker.mMisspelling);70 } catch (e) {71 return [];72 }73 let suggestions = new Array(5);74 for (let i = 0; i < 5; ++i) {75 suggestions[i] = spellChecker.GetSuggestedWord();76 if (suggestions[i].length === 0) {77 suggestions.length = i;78 break;79 }80 }81 this._spellChecker.mSpellSuggestions = suggestions;82 return suggestions;83 },84 _messages: [85 "InlineSpellChecker:selectDictionary",86 "InlineSpellChecker:replaceMisspelling",87 "InlineSpellChecker:toggleEnabled",88 "InlineSpellChecker:recheck",89 "InlineSpellChecker:uninit"90 ],91 _addMessageListeners() {92 for (let i of this._messages)93 this._manager.addMessageListener(i, this);94 },95 receiveMessage(msg) {96 switch (msg.name) {97 case "InlineSpellChecker:selectDictionary":98 this._spellChecker.selectDictionary(msg.data.index);99 break;100 case "InlineSpellChecker:replaceMisspelling":101 this._spellChecker.replaceMisspelling(msg.data.index);102 break;103 case "InlineSpellChecker:toggleEnabled":104 this._spellChecker.toggleEnabled();105 break;106 case "InlineSpellChecker:recheck":107 this._spellChecker.mInlineSpellChecker.enableRealTimeSpell = true;108 break;109 case "InlineSpellChecker:uninit":110 this.uninitContextMenu();111 break;112 }113 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const imposter = {3 {4 {5 is: {6 headers: { 'Content-Type': 'application/json' },7 body: JSON.stringify({ message: 'Hello world' })8 }9 }10 }11};12mb.create(imposter).then(() => {13 console.log('Imposter created');14 return mb.check('/imposters/3000');15}).then(response => {16 console.log('Imposter is up and running');17 console.log(response);18}).catch(error => {19 console.error(error);20});21const mb = require('mountebank');22const imposter = {23 {24 {25 is: {26 headers: { 'Content-Type': 'application/json' },27 body: JSON.stringify({ message: 'Hello world' })28 }29 }30 }31};32mb.create(imposter).then(() => {33 console.log('Imposter created');34 return mb.check('/imposters/3000');35}).then(response => {36 console.log('Imposter is up and running');37 console.log(response);38}).catch(error => {39 console.error(error);40});41const mb = require('mountebank');42const imposter = {43 {44 {45 is: {46 headers: { 'Content-Type': 'application/json' },47 body: JSON.stringify({ message: 'Hello world' })48 }49 }50 }51};52mb.create(imposter).then(() => {53 console.log('Imposter created');54 return mb.check('/imposters/3000');55}).then(response => {56 console.log('Imposter is up and running');57 console.log(response);58}).catch(error => {59 console.error(error);60});

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = require('request');2var options = {3 json: {4 {5 {6 equals: {7 headers: {8 }9 }10 }11 {12 is: {13 headers: {14 },15 }16 }17 }18 }19};20request(options, function (error, response, body) {21 if (!error && response.statusCode == 200) {22 console.log(body);23 }24});25var request = require('request');26var options = {27 json: {28 {29 {30 equals: {31 headers: {32 }33 }34 }35 {36 is: {37 headers: {38 },39 }40 }41 }42 }43};44request(options, function (error, response, body) {45 if (!error && response.statusCode == 200) {46 console.log(body);47 }48});49var request = require('request');50var options = {51 json: {52 {53 {54 equals: {55 headers: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var port = 2525;3var protocol = 'http';4var imposter = {5 {6 {7 equals: {8 }9 }10 {11 is: {12 }13 }14 }15};16mb.create(imposter).then(function (imposter) {17 return mb.get('/imposters/' + imposter.port);18}).then(function (response) {19 console.log(response.body);20 return mb.del('/imposters/' + imposter.port);21}).then(function () {22 console.log('done');23});24var mb = require('mountebank');25var port = 2525;26var protocol = 'http';27var imposter = {28 {29 {30 equals: {31 }32 }33 {34 is: {35 }36 }37 }38};39mb.create(imposter).then(function (imposter) {40 return mb.get('/imposters/' + imposter.port);41}).then(function (response) {42 console.log(response.body);43 return mb.del('/imposters/' + imposter.port);44}).then(function () {45 console.log('done');46});47var mb = require('mountebank');48var port = 2525;49var protocol = 'http';50var imposter = {51 {52 {53 equals: {54 }55 }56 {57 is: {58 }59 }60 }61};62mb.create(imposter).then(function (imposter) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var port = 2525;4var host = 'localhost';5var imposter = {6 {7 {8 equals: {9 }10 }11 {12 is: {13 headers: {14 },15 }16 }17 }18};19mb.create(url, imposter).then(function (response) {20 assert.equal(response.statusCode, 201);21 return mb.check(url, imposter, 0);22}).then(function (response) {23 assert.equal(response.statusCode, 200);24 console.log('Success!');25}).catch(function (error) {26 console.error('Error', error);27});28- [Mountebank Github](

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var assert = require('assert');3var port = 2525;4var imposterPort = 3000;5var protocol = 'http';6var stub = {7 {8 is: {9 headers: {10 },11 }12 }13};14var imposter = {15};16mb.create({ port: port, pidfile: 'mb.pid', logfile: 'mb.log' }, function (error) {17 assert.ifError(error);18 mb.post('/imposters', imposter, function (error) {19 assert.ifError(error);20 mb.get('/imposters', function (error, response) {21 assert.ifError(error);22 assert.equal(response.statusCode, 200);23 var imposters = JSON.parse(response.body);24 assert.equal(imposters.length, 1);25 assert.equal(imposters[0].port, imposterPort);26 assert.equal(imposters[0].protocol, protocol);27 mb.del('/imposters/3000', function (error, response) {28 assert.ifError(error);29 assert.equal(response.statusCode, 200);30 mb.del('/imposters', function (error) {31 assert.ifError(error);32 mb.stop(function (error) {33 assert.ifError(error);34 });35 });36 });37 });38 });39});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var imposter = mb.create({port: 2525});3imposter.post('/test', function (request, response) {4 response.statusCode = 200;5 response.body = {6 };7 response.send();8});9imposter.start();10{"name":"test","value":"test"}11{"name":"test","value":"test"}12{"name":"test","value":"test"}13{"name":"test","value":"test"}14{"name":"test","value":"test"}15{"name":"test","value":"test"}16{"name":"test","value":"test"}17{"name":"test","value":"test"}

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var assert = require('assert');3var Q = require('q');4var options = {5};6mb.start(options).then(function (imposter) {7 console.log('Imposter ' + imposter.port + ' started');8 var stub = {9 {10 equals: {11 }12 }13 {14 is: {15 }16 }17 };18 var promise = mb.post('/imposters', {19 });20 promise.then(function (response) {21 assert.equal(response.statusCode, 201);22 console.log('Imposter created');23 var request = require('request');24 var options = {25 };26 request(options, function (error, response, body) {27 if (!error && response.statusCode == 200) {28 console.log('Request sent');29 var promise = mb.get('/logs');30 promise.then(function (response) {31 assert.equal(response.statusCode, 200);32 var logs = JSON.parse(response.body);33 console.log('Logs received');34 var promise = mb.get('/imposters/4545');35 promise.then(function (response) {36 assert.equal(response.statusCode, 200);37 var imposter = JSON.parse(response.body);38 console.log('Imposter received');39 mb.stop().then(function

Full Screen

Using AI Code Generation

copy

Full Screen

1const request = require('request');2const assert = require('assert');3describe('Test', function() {4 it('should pass', function(done) {5 assert.equal(res.statusCode, 200);6 assert.equal(JSON.parse(body).numberOfRequests, 1);7 done();8 });9 });10});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful