House Democratic leaders survived a crucial test on the fiscal 1979 budget yesterday by defeating an amendment that would have cut spending across the board by 2 percent.

The victory persuaded top House Democrats they now have enough votes to win approval of a resolution setting preliminary targets for next year's budget.

But it took considerable arm-twisting by House Speaker Thomas P. O'Neill Jr. (D-Mass.) and Majority Leader Jim Wright (D-Tex.) to induce more than a dozen Democrats to switch their votes after formal voting time had expired on the amendment offered by Rep. Joseph L. Fisher (D-Va.), and a final vote on he resolution is expected to be close.

The Fisher amendment was finally defeated 195 to 203.

The leadership failed to stop the House from expressing its displeasure with the Panama Canal Treaty in the 1979 target budget resolution and could not black an amendment by Rep. John Ashbrook (R-Ohio), that trimmed $3.15 billion of "excess spending" from the department of Health, Education and Welfare's budget.

Nevertheless Budget Committee Chairman Robert N. Giaimo (D-Conn.), said he is optimistic that the House will approve the $500 billion budget.

This budget, which the House and Senate are supposed to agree on by May 15, serves as an initial guide to taxing and spending legislation. By mid-September Congress must approve a binding budget for the fiscal year that begins Oct. 1.

Last year, in a raucous session that went until 1 a.m., the House failed to pass a budget resolution after tacking on a series of amendments that boosted spending in many areas. The committee had to go back and rewrite its spring target budget.

One top Republican aide note that if the Republicans vote nearly unanimously against the resolution as they did last year, the Democrats will have trouble getting enough votes to pass it. Republicans oppose the size of the projected $55 billion deficit.

Ashbrook in introducing his amendment cited a General Accounting Office study that charged between $6.3 billion and $7.4 billion in HEW spending was unnecessary because of fraud, mismanagement and waste. Over strenuous objections of the Budget Committee the House approved the Ashbrook amendment 198 to 189.

Giaimo said he thinks the House will reverse itself today.

The House voted 230 to 171 to put all funds for the Panama Canal in the formal budget, subject to congressional appropriations. Currently the taxes and tolls collected from the canal are held in a trust fund in the U. S. Treasury and transferred to the Panama Canal.

The vote has no formal significance, its sponsor Rep. George Hansen (R-Idaho) conceded, but said it does send a signal to the president that the House is unhappy with the Canal treaties.

Giaimo said the crucial test yesterday was the Fisher amendment. "If we lost that we probably would have lost the resolution," he said.

Giaimo conceded that both the Fisher and Ashbrook amendments were "attractive" vehicles for members to signal their constituents that the House is concerned about inflation, the federal deficit and big government spending.

"But attaching amendments to the budget is not the way to do it," he said. "The way to do it is by catching programs when they start up."

He noted, for example, that the Ashbrook amendment would require a 5 percent reduction in funds for Medicare and Medicaid.

Similarly, Giaimo said, because 75 percent of all federal spending is mandated by laws passed in earlier years or by laws passed in earlier years or by entitlement programs such as Social Security where beneficiaries receive payments if they meet certain criteria, a 2 percent cut in spending could not be spread evenly over the $500 billion budget.