test: added test for coerce_to_object on Array

This commit is contained in:
Jose Acevedo 2022-01-17 21:29:47 -08:00
parent 36e808d2a6
commit 9a4f8cf32c
4 changed files with 12 additions and 0 deletions

View file

@ -25,6 +25,7 @@ Generated by [AVA](https://avajs.dev).
/** Gets some numbers */␊
export function getNums(): Array<number>
export function sumNums(nums: Array<number>): number␊
export function toJsObj(): object␊
export function readFileAsync(path: string): Promise<Buffer>
export function asyncMultiTwo(arg: number): Promise<number>
export function bigintAdd(a: bigint, b: bigint): bigint␊

View file

@ -15,6 +15,7 @@ export function getWords(): Array<string>
/** Gets some numbers */
export function getNums(): Array<number>
export function sumNums(nums: Array<number>): number
export function toJsObj(): object
export function readFileAsync(path: string): Promise<Buffer>
export function asyncMultiTwo(arg: number): Promise<number>
export function bigintAdd(a: bigint, b: bigint): bigint

View file

@ -1,3 +1,5 @@
use napi::{Env, JsObject};
#[napi]
pub fn get_words() -> Vec<&'static str> {
vec!["foo", "bar"]
@ -13,3 +15,11 @@ fn get_nums() -> Vec<u32> {
fn sum_nums(nums: Vec<u32>) -> u32 {
nums.iter().sum()
}
#[napi]
fn to_js_obj(env: Env) -> napi::Result<JsObject> {
let mut arr = env.create_array(0)?;
arr.insert("a string")?;
arr.insert(42)?;
arr.coerce_to_object()
}