本文整理汇总了TypeScript中factory-girl.factory.define方法的典型用法代码示例。如果您正苦于以下问题:TypeScript factory.define方法的具体用法?TypeScript factory.define怎么用?TypeScript factory.define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类factory-girl.factory
的用法示例。
在下文中一共展示了factory.define方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createPiece
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊♜⚊⚊⚊
⚊⚊♜⚊⚊⚊⚊⚊
*/
factory.define("board-rook-movement", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("e2", PieceType.Rook, PieceColor.White, true, model),
createPiece("c1", PieceType.Rook, PieceColor.White, true, model),
];
return model;
},
});
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊♖⚊⚊⚊
⚊⚊⚊⚊♖⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊♜⚊⚊⚊
⚊⚊⚊⚊♜⚊⚊⚊
*/
示例2: createPiece
/* Board Description
⚊⚊⚊⚊⚊♚⚊⚊
⚊⚊⚊⚊⚊♟⚊⚊
⚊⚊⚊⚊♗♔⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
*/
factory.define("board-stalemate-1", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("f8", PieceType.King, PieceColor.Black, true, model),
createPiece("f7", PieceType.Pawn, PieceColor.Black, false, model),
createPiece("e6", PieceType.Pawn, PieceColor.White, true, model),
createPiece("f6", PieceType.King, PieceColor.White, true, model),
]
return model
},
})
/* Board Description
⚊♝⚊⚊⚊⚊⚊♖
♚⚊⚊⚊⚊⚊⚊⚊
⚊♔⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
示例3: createPiece
import { factory } from "factory-girl"
import BoardBase from "../../src/common/BoardBase"
import { PieceColor, PieceType } from "../../src/common/GamePieces"
import { createPiece, stringToPosition } from "./BoardHelper"
// king vs king
factory.define("board-draw-notenoughpieces-1", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("e7", PieceType.King, PieceColor.Black, true, model),
createPiece("e2", PieceType.King, PieceColor.White, true, model),
createPiece("e3", PieceType.Pawn, PieceColor.Black, true, model),
]
return model
},
})
// King + bishop vs King + bishop on the same color
factory.define("board-draw-notenoughpieces-2", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("e7", PieceType.King, PieceColor.Black, true, model),
createPiece("e2", PieceType.King, PieceColor.White, true, model),
createPiece("c2", PieceType.Bishop, PieceColor.White, true, model),
createPiece("f7", PieceType.Bishop, PieceColor.Black, true, model),
createPiece("e3", PieceType.Pawn, PieceColor.Black, true, model),
]
return model
},
示例4: createPiece
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊♜⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊♔⚊⚊⚊⚊⚊
*/
factory.define("board-check", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("b3", PieceType.Rook, PieceColor.Black, false, model),
createPiece("c1", PieceType.King, PieceColor.White, false, model),
]
return model
},
})
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊♞⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
♖⚊♜♔⚊⚊⚊⚊
*/
示例5: createPiece
⚊⚊⚊⚊⚊⚊♙⚊
⚊⚊⚊⚊⚊♙⚊⚊
♙♙♙♙♙⚊⚊♙
⚊⚊⚊♕♔♗⚊⚊
*/
factory.define("board-foolsmate", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("a2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("b2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("c2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("d2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("e2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("f3", PieceType.Pawn, PieceColor.White, true, model),
createPiece("g4", PieceType.Pawn, PieceColor.White, true, model),
createPiece("h2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("d1", PieceType.Queen, PieceColor.White, false, model),
createPiece("e1", PieceType.King, PieceColor.White, false, model),
createPiece("f1", PieceType.Bishop, PieceColor.White, false, model),
createPiece("d8", PieceType.Queen, PieceColor.Black, true, model),
]
return model
},
})
/* Board Description
⚊♕⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊♟♚⚊
⚊⚊♟⚊⚊⚊♟⚊
示例6: createPiece
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊♕♗⚊⚊⚊
♖⚊⚊⚊♔⚊⚊♖
*/
factory.define("board-castling", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("a1", PieceType.Rook, PieceColor.White, false, model),
createPiece("d2", PieceType.Queen, PieceColor.White, false, model),
createPiece("e1", PieceType.King, PieceColor.White, false, model),
createPiece("e2", PieceType.Bishop, PieceColor.White, false, model),
createPiece("h1", PieceType.Rook, PieceColor.White, false, model),
];
return model;
},
});
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
♜⚊⚊⚊⚊⚊⚊⚊
示例7: createPiece
import { factory } from "factory-girl";
import BoardBase from "../../src/common/BoardBase";
import { PieceColor, PieceType } from "../../src/common/GamePieces"
import { createPiece } from "./BoardHelper"
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
♙⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊♙⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊♟⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
*/
factory.define("board-enpassant", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("c2", PieceType.Pawn, PieceColor.White, false, model),
createPiece("d4", PieceType.Pawn, PieceColor.Black, true, model),
createPiece("a7", PieceType.Pawn, PieceColor.Black, false, model),
];
return model;
},
});
export default factory;
示例8: createPiece
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊♙⚊⚊
♖♘♗♕♔⚊⚊
*/
factory.define("board-an-movement", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("a1", PieceType.Rook, PieceColor.White, false, model),
createPiece("b1", PieceType.Knight, PieceColor.White, false, model),
createPiece("c1", PieceType.Bishop, PieceColor.White, false, model),
createPiece("d1", PieceType.Queen, PieceColor.White, false, model),
createPiece("e1", PieceType.King, PieceColor.White, false, model),
createPiece("f2", PieceType.Pawn, PieceColor.White, false, model),
]
return model
},
})
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊♟⚊⚊⚊⚊⚊⚊
♟⚊⚊⚊⚊⚊⚊⚊
♟⚊⚊⚊⚊⚊⚊⚊
示例9: createPiece
import { factory } from "factory-girl";
import BoardBase from "../../src/common/BoardBase";
import { PieceColor, PieceType } from "../../src/common/GamePieces"
import { createPiece } from "./BoardHelper"
factory.define("board", BoardBase, {});
/* Board Description
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊♙♟♟⚊⚊⚊
⚊⚊⚊♙♙♟⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
*/
factory.define("board-pawn-capture", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("c5", PieceType.Pawn, PieceColor.White, true, model),
createPiece("d5", PieceType.Pawn, PieceColor.Black, true, model),
createPiece("e5", PieceType.Pawn, PieceColor.Black, true, model),
createPiece("d4", PieceType.Pawn, PieceColor.White, true, model),
createPiece("e4", PieceType.Pawn, PieceColor.White, true, model),
createPiece("f4", PieceType.Pawn, PieceColor.Black, true, model),
];
return model;
},
});
示例10: createPiece
/* Board Description ♔♚
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊♔⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
*/
factory.define("board-king-movement", BoardBase, {}, {
afterBuild: (model, attrs, buildOptions) => {
model.pieces = [
createPiece("c2", PieceType.King, PieceColor.White, true, model),
];
return model;
},
});
/* Board Description ♔♚ ♟♙
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊⚊⚊⚊⚊⚊⚊⚊
⚊♟⚊⚊⚊⚊⚊⚊
⚊♟♔⚊⚊⚊⚊⚊
⚊⚊♙⚊⚊⚊⚊⚊
*/