mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 19:43:29 +01:00
feat(embed): add setFields (#7322)
This commit is contained in:
@@ -391,6 +391,22 @@ describe('Embed', () => {
|
|||||||
).toThrowError();
|
).toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('GIVEN an embed using Embed#setFields THEN returns valid toJSON data', () => {
|
||||||
|
const embed = new Embed();
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
embed.setFields(...Array.from({ length: 25 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||||
|
).not.toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GIVEN an embed using Embed#setFields that sets more than 25 fields THEN throws error', () => {
|
||||||
|
const embed = new Embed();
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
embed.setFields(...Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||||
|
).toThrowError();
|
||||||
|
});
|
||||||
|
|
||||||
describe('GIVEN invalid field amount THEN throws error', () => {
|
describe('GIVEN invalid field amount THEN throws error', () => {
|
||||||
test('', () => {
|
test('', () => {
|
||||||
const embed = new Embed();
|
const embed = new Embed();
|
||||||
|
|||||||
@@ -170,6 +170,15 @@ export class Embed implements APIEmbed {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the embed's fields (max 25).
|
||||||
|
* @param fields The fields to set
|
||||||
|
*/
|
||||||
|
public setFields(...fields: APIEmbedField[]) {
|
||||||
|
this.spliceFields(0, this.fields.length, ...fields);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the author of this embed
|
* Sets the author of this embed
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user