(t *testing.T)
| 436 | } |
| 437 | |
| 438 | func TestModuleFailures(t *testing.T) { |
| 439 | t.Parallel() |
| 440 | |
| 441 | t.Run("invoke from submodule failed", func(t *testing.T) { |
| 442 | t.Parallel() |
| 443 | |
| 444 | type A struct{} |
| 445 | type B struct{} |
| 446 | |
| 447 | sub := fx.Module("sub", |
| 448 | fx.Provide(func() *A { return &A{} }), |
| 449 | fx.Invoke(func(*A, *B) { // missing dependency. |
| 450 | require.Fail(t, "this should not be called") |
| 451 | }), |
| 452 | ) |
| 453 | |
| 454 | app := NewForTest(t, |
| 455 | sub, |
| 456 | fx.Invoke(func(a *A) { |
| 457 | assert.NotNil(t, a) |
| 458 | }), |
| 459 | ) |
| 460 | |
| 461 | err := app.Err() |
| 462 | require.Error(t, err) |
| 463 | assert.Contains(t, err.Error(), "missing type: *fx_test.B") |
| 464 | }) |
| 465 | |
| 466 | t.Run("provide the same dependency from multiple modules", func(t *testing.T) { |
| 467 | t.Parallel() |
| 468 | |
| 469 | type A struct{} |
| 470 | |
| 471 | app := NewForTest(t, |
| 472 | fx.Module("mod1", fx.Provide(func() A { return A{} })), |
| 473 | fx.Module("mod2", fx.Provide(func() A { return A{} })), |
| 474 | fx.Invoke(func(a A) {}), |
| 475 | ) |
| 476 | |
| 477 | err := app.Err() |
| 478 | require.Error(t, err) |
| 479 | assert.Contains(t, err.Error(), "already provided by ") |
| 480 | }) |
| 481 | |
| 482 | t.Run("providing Modules should fail", func(t *testing.T) { |
| 483 | t.Parallel() |
| 484 | app := NewForTest(t, |
| 485 | fx.Module("module", |
| 486 | fx.Provide( |
| 487 | fx.Module("module"), |
| 488 | ), |
| 489 | ), |
| 490 | ) |
| 491 | err := app.Err() |
| 492 | require.Error(t, err) |
| 493 | assert.Contains(t, err.Error(), "fx.Option should be passed to fx.New directly, not to fx.Provide") |
| 494 | }) |
| 495 |
nothing calls this directly
no test coverage detected