pokemon-showdown/test/sim/dex.js
Guangcong Luo 13189fdb02
Update Dex API (#8181)
This is the change that renames:

- `Dex.getMove` -> `Dex.moves.get`
- `Dex.getAbility` -> `Dex.abilities.get`
- `Dex.getItem` -> `Dex.items.get`
- `Dex.getSpecies` -> `Dex.species.get`
- `Dex.getEffect` -> `Dex.conditions.get`
- `Dex.getNature` -> `Dex.natures.get`
- `Dex.getType` -> `Dex.types.get`
- `Dex.getFormat` -> `Dex.formats.get`

In addition, some other APIs have been updated:

- `getByID` methods have also been added to every other table.
- `Dex.moves.all()` now gets an array of all moves
  - Plus equivalent methods for `abilities`, `items`, `species`, `formats`, `natures`, `types`
  - Note: there's no `Dex.conditions.all()`
- new API: `Dex.stats` for naming/iterating stats
- `Dex.getEffectByID` -> `Dex.conditions.getByID`
- `Dex.getType` -> `Dex.types.get`
- `Dex.data.Formats` -> `Dex.data.Rulesets`
- `Dex.formats` -> now an array `Dex.formats.all()`
- `Dex.getRuleTable` -> `Dex.formats.getRuleTable`
- `Dex.validateFormat` -> `Dex.formats.validate`

Team functions have been split off into a new `sim/teams` package:

- `Dex.packTeam` -> `Teams.pack`
- `Dex.fastUnpackTeam` -> `Teams.unpack`
- `Dex.generateTeam` -> `Teams.generate`
- `Dex.stringifyTeam` -> `Teams.export`

`Teams.export` has also been rewritten to better match how it works in client.

This implements #8178
2021-04-08 03:00:37 -07:00

70 lines
2.6 KiB
JavaScript

'use strict';
const assert = require('./../assert');
describe('Mod loader', function () {
it('should work fine in any order', function () {
{
const Dex = require('./../../.sim-dist/dex').Dex;
assert.equal(Dex.mod('gen2').species.getLearnset('nidoking').bubblebeam.join(','), '1M');
assert.equal(Dex.mod('gen2').moves.get('crunch').secondaries[0].boosts.def, undefined);
}
{
const Dex = require('./../../.sim-dist/dex').Dex;
Dex.mod('gen2').species.getLearnset('nidoking');
Dex.mod('gen4').moves.get('crunch');
assert.equal(Dex.mod('gen2').species.getLearnset('nidoking').bubblebeam.join(','), '1M');
assert.equal(Dex.mod('gen2').moves.get('crunch').secondaries[0].boosts.def, undefined);
}
});
});
describe('Dex#getEffect', function () {
it('returns the same object for the same id', function () {
assert.equal(Dex.conditions.get('Stealth Rock'), Dex.conditions.get('stealthrock'));
assert.notEqual(Dex.conditions.get('move: Stealth Rock'), Dex.conditions.get('stealthrock'));
});
it('does not return elements from the Object prototype', function () {
assert.false(Dex.conditions.get('constructor').exists);
});
});
describe('Dex#getSpecies', function () {
it('should handle cosmetic Flabébé formes', function () {
assert.equal(Dex.species.get('Flabébé-yellow').name, 'Flabébé-Yellow');
});
it('should handle Minior-Meteor formes', function () {
assert(Dex.species.get('Minior-Meteor').isNonstandard);
assert(!Dex.forGen(7).species.get('Minior-Meteor').isNonstandard);
});
it.skip('should handle Rockruff-Dusk', function () {
assert.equal(Dex.species.get('rockruffdusk').name, 'Rockruff-Dusk');
});
it('should handle Pikachu forme numbering', function () {
assert.deepEqual(
Dex.forGen(6).species.get('Pikachu').formeOrder.slice(0, 7),
["Pikachu", "Pikachu-Rock-Star", "Pikachu-Belle", "Pikachu-Pop-Star", "Pikachu-PhD", "Pikachu-Libre", "Pikachu-Cosplay"]
);
assert.deepEqual(
Dex.forGen(7).species.get('Pikachu').formeOrder.slice(0, 9),
["Pikachu", "Pikachu-Original", "Pikachu-Hoenn", "Pikachu-Sinnoh", "Pikachu-Unova", "Pikachu-Kalos", "Pikachu-Alola", "Pikachu-Partner", "Pikachu-Starter"]
);
});
});
describe('Dex#getItem', function () {
it('should not mark Gems as as Nonstandard in Gens 5-7', function () {
assert(!Dex.forGen(5).items.get('Rock Gem').isNonstandard);
assert(!Dex.forGen(5).items.get('Normal Gem').isNonstandard);
assert(Dex.forGen(6).items.get('Rock Gem').isNonstandard === 'Unobtainable');
assert(!Dex.forGen(6).items.get('Normal Gem').isNonstandard);
assert(Dex.forGen(8).items.get('Rock Gem').isNonstandard === 'Past');
});
});